Compare commits

..

1 Commits

Author SHA1 Message Date
Spring Builds 850cb6c4c9 Release v5.3.12 2021-10-21 05:44:20 +00:00
287 changed files with 1647 additions and 3068 deletions
+49 -49
View File
@@ -3,8 +3,8 @@ plugins {
id 'io.spring.nohttp' version '0.0.10'
id "io.freefair.aspectj" version '6.2.0' apply false
id 'org.jetbrains.dokka' version '1.5.0' apply false
id 'org.jetbrains.kotlin.jvm' version '1.5.32' apply false
id "org.jetbrains.kotlin.plugin.serialization" version "1.5.32" apply false
id 'org.jetbrains.kotlin.jvm' version '1.5.31' apply false
id "org.jetbrains.kotlin.plugin.serialization" version "1.5.31" apply false
id 'org.asciidoctor.jvm.convert' version '3.3.2'
id 'org.asciidoctor.jvm.pdf' version '3.3.2'
id "org.unbroken-dome.xjc" version '2.0.0' apply false
@@ -27,19 +27,19 @@ configure(allprojects) { project ->
dependencyManagement {
imports {
mavenBom "com.fasterxml.jackson:jackson-bom:2.12.6"
mavenBom "io.netty:netty-bom:4.1.72.Final"
mavenBom "io.projectreactor:reactor-bom:2020.0.15"
mavenBom "io.r2dbc:r2dbc-bom:Arabba-SR11"
mavenBom "com.fasterxml.jackson:jackson-bom:2.12.5"
mavenBom "io.netty:netty-bom:4.1.69.Final"
mavenBom "io.projectreactor:reactor-bom:2020.0.12"
mavenBom "io.r2dbc:r2dbc-bom:Arabba-SR10"
mavenBom "io.rsocket:rsocket-bom:1.1.1"
mavenBom "org.eclipse.jetty:jetty-bom:9.4.44.v20210927"
mavenBom "org.jetbrains.kotlin:kotlin-bom:1.5.32"
mavenBom "org.jetbrains.kotlin:kotlin-bom:1.5.31"
mavenBom "org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.5.2"
mavenBom "org.jetbrains.kotlinx:kotlinx-serialization-bom:1.2.2"
mavenBom "org.junit:junit-bom:5.8.2"
mavenBom "org.junit:junit-bom:5.8.1"
}
dependencies {
dependencySet(group: 'org.apache.logging.log4j', version: '2.17.1') {
dependencySet(group: 'org.apache.logging.log4j', version: '2.14.1') {
entry 'log4j-api'
entry 'log4j-core'
entry 'log4j-jul'
@@ -67,23 +67,23 @@ configure(allprojects) { project ->
dependency "io.reactivex:rxjava:1.3.8"
dependency "io.reactivex:rxjava-reactive-streams:1.2.1"
dependency "io.reactivex.rxjava2:rxjava:2.2.21"
dependency "io.reactivex.rxjava3:rxjava:3.1.3"
dependency "io.smallrye.reactive:mutiny:1.2.0"
dependency "io.reactivex.rxjava3:rxjava:3.1.1"
dependency "io.smallrye.reactive:mutiny:1.1.1"
dependency "io.projectreactor.tools:blockhound:1.0.6.RELEASE"
dependency "com.caucho:hessian:4.0.63"
dependency "com.fasterxml:aalto-xml:1.3.0"
dependency("com.fasterxml.woodstox:woodstox-core:6.2.7") {
dependency("com.fasterxml.woodstox:woodstox-core:6.2.6") {
exclude group: "stax", name: "stax-api"
}
dependency "com.google.code.gson:gson:2.8.9"
dependency "com.google.protobuf:protobuf-java-util:3.19.1"
dependency "com.google.code.gson:gson:2.8.8"
dependency "com.google.protobuf:protobuf-java-util:3.18.0"
dependency "com.googlecode.protobuf-java-format:protobuf-java-format:1.4"
dependency("com.thoughtworks.xstream:xstream:1.4.18") {
exclude group: "xpp3", name: "xpp3_min"
exclude group: "xmlpull", name: "xmlpull"
}
dependency "org.apache.johnzon:johnzon-jsonb:1.2.15"
dependency "org.apache.johnzon:johnzon-jsonb:1.2.14"
dependency("org.codehaus.jettison:jettison:1.3.8") {
exclude group: "stax", name: "stax-api"
}
@@ -92,10 +92,10 @@ configure(allprojects) { project ->
entry 'jibx-run'
}
dependency "org.ogce:xpp3:1.1.6"
dependency "org.yaml:snakeyaml:1.30"
dependency "org.yaml:snakeyaml:1.29"
dependency "com.h2database:h2:2.0.206"
dependency "com.github.ben-manes.caffeine:caffeine:2.9.3"
dependency "com.h2database:h2:1.4.200"
dependency "com.github.ben-manes.caffeine:caffeine:2.9.2"
dependency "com.github.librepdf:openpdf:1.3.26"
dependency "com.rometools:rome:1.16.0"
dependency "commons-io:commons-io:2.5"
@@ -123,48 +123,48 @@ configure(allprojects) { project ->
dependency "net.sf.ehcache:ehcache:2.10.6"
dependency "org.ehcache:jcache:1.0.1"
dependency "org.ehcache:ehcache:3.4.0"
dependency "org.hibernate:hibernate-core:5.4.33.Final"
dependency "org.hibernate:hibernate-validator:6.2.1.Final"
dependency "org.hibernate:hibernate-core:5.4.32.Final"
dependency "org.hibernate:hibernate-validator:6.2.0.Final"
dependency "org.webjars:webjars-locator-core:0.48"
dependency "org.webjars:underscorejs:1.8.3"
dependencySet(group: 'org.apache.tomcat', version: '9.0.56') {
dependencySet(group: 'org.apache.tomcat', version: '9.0.53') {
entry 'tomcat-util'
entry('tomcat-websocket') {
exclude group: "org.apache.tomcat", name: "tomcat-servlet-api"
exclude group: "org.apache.tomcat", name: "tomcat-websocket-api"
exclude group: "org.apache.tomcat", name: "tomcat-servlet-api"
}
}
dependencySet(group: 'org.apache.tomcat.embed', version: '9.0.56') {
dependencySet(group: 'org.apache.tomcat.embed', version: '9.0.53') {
entry 'tomcat-embed-core'
entry 'tomcat-embed-websocket'
}
dependencySet(group: 'io.undertow', version: '2.2.14.Final') {
dependencySet(group: 'io.undertow', version: '2.2.12.Final') {
entry 'undertow-core'
entry('undertow-websockets-jsr') {
exclude group: "org.jboss.spec.javax.websocket", name: "jboss-websocket-api_1.1_spec"
}
entry('undertow-servlet') {
exclude group: "org.jboss.spec.javax.servlet", name: "jboss-servlet-api_4.0_spec"
exclude group: "org.jboss.spec.javax.annotation", name: "jboss-annotations-api_1.3_spec"
}
entry('undertow-websockets-jsr') {
exclude group: "org.jboss.spec.javax.websocket", name: "jboss-websocket-api_1.1_spec"
}
}
dependency "org.eclipse.jetty:jetty-reactive-httpclient:1.1.10"
dependency 'org.apache.httpcomponents.client5:httpclient5:5.1.2'
dependency 'org.apache.httpcomponents.core5:httpcore5-reactive:5.1.2'
dependency("org.apache.httpcomponents:httpclient:4.5.13") {
exclude group: "commons-logging", name: "commons-logging"
}
dependency("org.apache.httpcomponents:httpasyncclient:4.1.5") {
exclude group: "commons-logging", name: "commons-logging"
}
dependencySet(group: 'com.squareup.okhttp3', version: '3.14.9') {
entry 'okhttp'
entry 'mockwebserver'
}
dependency("org.apache.httpcomponents:httpclient:4.5.13") {
exclude group: "commons-logging", name: "commons-logging"
}
dependency("org.apache.httpcomponents:httpasyncclient:4.1.4") {
exclude group: "commons-logging", name: "commons-logging"
}
dependency 'org.apache.httpcomponents.client5:httpclient5:5.1'
dependency 'org.apache.httpcomponents.core5:httpcore5-reactive:5.1.1'
dependency "org.eclipse.jetty:jetty-reactive-httpclient:1.1.9"
dependency "org.jruby:jruby:9.2.20.1"
dependency "org.jruby:jruby:9.2.19.0"
dependency "org.python:jython-standalone:2.7.1"
dependency "org.mozilla:rhino:1.7.11"
@@ -191,25 +191,25 @@ configure(allprojects) { project ->
dependency "org.junit.support:testng-engine:1.0.1"
dependency "org.hamcrest:hamcrest:2.1"
dependency "org.awaitility:awaitility:3.1.6"
dependency "org.assertj:assertj-core:3.22.0"
dependencySet(group: 'org.xmlunit', version: '2.8.4') {
dependency "org.assertj:assertj-core:3.21.0"
dependencySet(group: 'org.xmlunit', version: '2.8.2') {
entry 'xmlunit-assertj'
entry('xmlunit-matchers') {
exclude group: "org.hamcrest", name: "hamcrest-core"
}
}
dependencySet(group: 'org.mockito', version: '4.2.0') {
dependencySet(group: 'org.mockito', version: '4.0.0') {
entry('mockito-core') {
exclude group: "org.hamcrest", name: "hamcrest-core"
}
entry 'mockito-junit-jupiter'
}
dependency "io.mockk:mockk:1.12.1"
dependency "io.mockk:mockk:1.12.0"
dependency("net.sourceforge.htmlunit:htmlunit:2.56.0") {
dependency("net.sourceforge.htmlunit:htmlunit:2.53.0") {
exclude group: "commons-logging", name: "commons-logging"
}
dependency("org.seleniumhq.selenium:htmlunit-driver:2.56.0") {
dependency("org.seleniumhq.selenium:htmlunit-driver:2.53.0") {
exclude group: "commons-logging", name: "commons-logging"
}
dependency("org.seleniumhq.selenium:selenium-java:3.141.59") {
@@ -237,7 +237,7 @@ configure(allprojects) { project ->
dependency "com.ibm.websphere:uow:6.0.2.17"
dependency "com.jamonapi:jamon:2.82"
dependency "joda-time:joda-time:2.10.13"
dependency "joda-time:joda-time:2.10.10"
dependency "org.eclipse.persistence:org.eclipse.persistence.jpa:2.7.9"
dependency "org.javamoney:moneta:1.3"
@@ -340,7 +340,7 @@ configure([rootProject] + javaProjects) { project ->
}
checkstyle {
toolVersion = "9.2"
toolVersion = "9.0"
configDirectory.set(rootProject.file("src/checkstyle"))
}
@@ -353,12 +353,12 @@ configure([rootProject] + javaProjects) { project ->
testImplementation("io.mockk:mockk")
testImplementation("org.assertj:assertj-core")
// Pull in the latest JUnit 5 Launcher API to ensure proper support in IDEs.
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testRuntimeOnly("org.junit.platform:junit-platform-suite-engine")
testRuntimeOnly("org.apache.logging.log4j:log4j-core")
testRuntimeOnly("org.apache.logging.log4j:log4j-jul")
testRuntimeOnly("org.apache.logging.log4j:log4j-slf4j-impl")
testRuntimeOnly("org.apache.logging.log4j:log4j-jul")
// JSR-305 only used for non-required meta-annotations
compileOnly("com.google.code.findbugs:jsr305")
testCompileOnly("com.google.code.findbugs:jsr305")
@@ -383,9 +383,9 @@ configure([rootProject] + javaProjects) { project ->
"https://hc.apache.org/httpcomponents-client-5.1.x/current/httpclient5/apidocs/",
"https://projectreactor.io/docs/test/release/api/",
"https://junit.org/junit4/javadoc/4.13.2/",
// Disabling linking to JUnit 5.8.2, since the `package-list` file no longer exists due to
// Disabling linking to JUnit 5.8.1, since the `package-list` file no longer exists due to
// https://github.com/junit-team/junit5/commit/67ad4e545518b0ce2b0e7c96df31a669866d5003.
// "https://junit.org/junit5/docs/5.8.2/api/",
// "https://junit.org/junit5/docs/5.8.1/api/",
"https://www.reactive-streams.org/reactive-streams-1.0.3-javadoc/",
"https://javadoc.io/static/io.rsocket/rsocket-core/1.1.1/",
"https://r2dbc.io/spec/0.8.5.RELEASE/api/"
+1 -1
View File
@@ -1,4 +1,4 @@
version=5.3.15
version=5.3.12
org.gradle.jvmargs=-Xmx1536M
org.gradle.caching=true
org.gradle.parallel=true
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -74,7 +74,7 @@ class ScheduledAndTransactionalAnnotationIntegrationTests {
MyRepository repository = ctx.getBean(MyRepository.class);
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
assertThat(AopUtils.isCglibProxy(repository)).isTrue();
assertThat(AopUtils.isCglibProxy(repository)).isEqualTo(true);
assertThat(repository.getInvocationCount()).isGreaterThan(0);
assertThat(txManager.commits).isGreaterThan(0);
}
+1 -1
View File
@@ -6,7 +6,7 @@ pluginManagement {
}
plugins {
id "com.gradle.enterprise" version "3.7.2"
id "com.gradle.enterprise" version "3.6.1"
id "io.spring.ge.conventions" version "0.0.7"
}
@@ -45,10 +45,9 @@ import org.springframework.core.NativeDetector;
* @see AdvisedSupport#setProxyTargetClass
* @see AdvisedSupport#setInterfaces
*/
@SuppressWarnings("serial")
public class DefaultAopProxyFactory implements AopProxyFactory, Serializable {
private static final long serialVersionUID = 7930414337282325166L;
@Override
public AopProxy createAopProxy(AdvisedSupport config) throws AopConfigException {
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -421,7 +421,11 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
* are unaffected by such changes.
*/
private synchronized void initializeAdvisorChain() throws AopConfigException, BeansException {
if (!this.advisorChainInitialized && !ObjectUtils.isEmpty(this.interceptorNames)) {
if (this.advisorChainInitialized) {
return;
}
if (!ObjectUtils.isEmpty(this.interceptorNames)) {
if (this.beanFactory == null) {
throw new IllegalStateException("No BeanFactory available anymore (probably due to serialization) " +
"- cannot resolve interceptor names " + Arrays.asList(this.interceptorNames));
@@ -460,9 +464,9 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
addAdvisorOnChainCreation(advice);
}
}
this.advisorChainInitialized = true;
}
this.advisorChainInitialized = true;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,8 +25,8 @@ import org.springframework.aop.Advisor;
import org.springframework.aop.ThrowsAdvice;
/**
* Adapter to enable {@link org.springframework.aop.ThrowsAdvice} to be used
* in the Spring AOP framework.
* Adapter to enable {@link org.springframework.aop.MethodBeforeAdvice}
* to be used in the Spring AOP framework.
*
* @author Rod Johnson
* @author Juergen Hoeller
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -322,7 +322,7 @@ abstract class AbstractAspectJAdvisorFactoryTests {
int b = 12;
int c = 25;
String d = "d";
StringBuilder e = new StringBuilder("stringbuf");
StringBuffer e = new StringBuffer("stringbuf");
String expectedResult = a + b+ c + d + e;
assertThat(mva.mungeArgs(a, b, c, d, e)).isEqualTo(expectedResult);
}
@@ -728,12 +728,12 @@ abstract class AbstractAspectJAdvisorFactoryTests {
@Aspect
static class ManyValuedArgs {
String mungeArgs(String a, int b, int c, String d, StringBuilder e) {
String mungeArgs(String a, int b, int c, String d, StringBuffer e) {
return a + b + c + d + e;
}
@Around(value="execution(String mungeArgs(..)) && args(a, b, c, d, e)", argNames="b,c,d,e,a")
String reverseAdvice(ProceedingJoinPoint pjp, int b, int c, String d, StringBuilder e, String a) throws Throwable {
String reverseAdvice(ProceedingJoinPoint pjp, int b, int c, String d, StringBuffer e, String a) throws Throwable {
assertThat(pjp.proceed()).isEqualTo(a + b+ c+ d+ e);
return a + b + c + d + e;
}
@@ -16,9 +16,9 @@
</aop:aspect>
</aop:config>
<bean id="getNameCounter" class="org.springframework.aop.testfixture.advice.CountingBeforeAdvice"/>
<bean id="getNameCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
<bean id="getAgeCounter" class="org.springframework.aop.testfixture.advice.CountingBeforeAdvice"/>
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
<bean id="testBean" class="org.springframework.beans.testfixture.beans.TestBean"/>
@@ -9,6 +9,6 @@
<aop:advisor advice-ref="countingAdvice" pointcut="within(org.springframework..*)"/>
</aop:config>
<bean id="countingAdvice" class="org.springframework.aop.testfixture.advice.CountingBeforeAdvice"/>
<bean id="countingAdvice" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
</beans>
@@ -10,6 +10,6 @@
<aop:advisor advice-ref="countingAdvice" pointcut-ref="pc"/>
</aop:config>
<bean id="countingAdvice" class="org.springframework.aop.testfixture.advice.CountingBeforeAdvice"/>
<bean id="countingAdvice" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
</beans>
@@ -12,7 +12,7 @@
</aop:aspect>
</aop:config>
<bean id="getAgeCounter" class="org.springframework.aop.testfixture.advice.CountingBeforeAdvice"/>
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
<bean id="testBean" class="org.springframework.beans.testfixture.beans.TestBean"/>
@@ -12,7 +12,7 @@
</aop:aspect>
</aop:config>
<bean id="getAgeCounter" class="org.springframework.aop.testfixture.advice.CountingBeforeAdvice"/>
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
<bean id="testBean" class="org.springframework.beans.testfixture.beans.TestBean"/>
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ package org.springframework.aop.testfixture.advice;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
/**
* Abstract superclass for counting advices etc.
@@ -32,7 +31,7 @@ import java.util.Map;
public class MethodCounter implements Serializable {
/** Method name --> count, does not understand overloading */
private Map<String, Integer> map = new HashMap<>();
private HashMap<String, Integer> map = new HashMap<>();
private int allCount;
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
@@ -106,7 +107,10 @@ public class AspectJEnableCachingIsolatedTests {
try {
load(MultiCacheManagerConfigurer.class, EnableCachingConfig.class);
}
catch (IllegalStateException ex) {
catch (BeanCreationException ex) {
Throwable root = ex.getRootCause();
boolean condition = root instanceof IllegalStateException;
assertThat(condition).isTrue();
assertThat(ex.getMessage().contains("implementations of CachingConfigurer")).isTrue();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -422,13 +422,10 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
}
if (editor == null) {
// Find editor for superclass or interface.
for (Map.Entry<Class<?>, PropertyEditor> entry : this.customEditors.entrySet()) {
if (editor != null) {
break;
}
Class<?> key = entry.getKey();
for (Iterator<Class<?>> it = this.customEditors.keySet().iterator(); it.hasNext() && editor == null;) {
Class<?> key = it.next();
if (key.isAssignableFrom(requiredType)) {
editor = entry.getValue();
editor = this.customEditors.get(key);
// Cache editor for search type, to avoid the overhead
// of repeated assignable-from checks.
if (this.customEditorCache == null) {
@@ -214,7 +214,6 @@ public interface BeanFactory {
/**
* Return a provider for the specified bean, allowing for lazy on-demand retrieval
* of instances, including availability and uniqueness options.
* <p>For matching a generic type, consider {@link #getBeanProvider(ResolvableType)}.
* @param requiredType type the bean must match; can be an interface or superclass
* @return a corresponding provider handle
* @since 5.1
@@ -224,20 +223,13 @@ public interface BeanFactory {
/**
* Return a provider for the specified bean, allowing for lazy on-demand retrieval
* of instances, including availability and uniqueness options. This variant allows
* for specifying a generic type to match, similar to reflective injection points
* with generic type declarations in method/constructor parameters.
* <p>Note that collections of beans are not supported here, in contrast to reflective
* of instances, including availability and uniqueness options.
* @param requiredType type the bean must match; can be a generic type declaration.
* Note that collection types are not supported here, in contrast to reflective
* injection points. For programmatically retrieving a list of beans matching a
* specific type, specify the actual bean type as an argument here and subsequently
* use {@link ObjectProvider#orderedStream()} or its lazy streaming/iteration options.
* <p>Also, generics matching is strict here, as per the Java assignment rules.
* For lenient fallback matching with unchecked semantics (similar to the ´unchecked´
* Java compiler warning), consider calling {@link #getBeanProvider(Class)} with the
* raw type as a second step if no full generic match is
* {@link ObjectProvider#getIfAvailable() available} with this variant.
* @return a corresponding provider handle
* @param requiredType type the bean must match; can be a generic type declaration
* @since 5.1
* @see ObjectProvider#iterator()
* @see ObjectProvider#stream()
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -353,31 +353,9 @@ public interface ListableBeanFactory extends BeanFactory {
* @since 3.0
* @see #getBeanNamesForAnnotation
* @see #getBeansWithAnnotation
* @see #getType(String)
*/
@Nullable
<A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType)
throws NoSuchBeanDefinitionException;
/**
* Find an {@link Annotation} of {@code annotationType} on the specified bean,
* traversing its interfaces and super classes if no annotation can be found on
* the given class itself, as well as checking the bean's factory method (if any).
* @param beanName the name of the bean to look for annotations on
* @param annotationType the type of annotation to look for
* (at class, interface or factory method level of the specified bean)
* @param allowFactoryBeanInit whether a {@code FactoryBean} may get initialized
* just for the purpose of determining its object type
* @return the annotation of the given type if found, or {@code null} otherwise
* @throws NoSuchBeanDefinitionException if there is no bean with the given name
* @since 5.3.14
* @see #getBeanNamesForAnnotation
* @see #getBeansWithAnnotation
* @see #getType(String, boolean)
*/
@Nullable
<A extends Annotation> A findAnnotationOnBean(
String beanName, Class<A> annotationType, boolean allowFactoryBeanInit)
throws NoSuchBeanDefinitionException;
}
@@ -459,7 +459,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA
return metadata;
}
private InjectionMetadata buildAutowiringMetadata(Class<?> clazz) {
private InjectionMetadata buildAutowiringMetadata(final Class<?> clazz) {
if (!AnnotationUtils.isCandidateClass(clazz, this.autowiredAnnotationTypes)) {
return InjectionMetadata.EMPTY;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,7 +34,9 @@ import org.springframework.lang.Nullable;
*
* <p><b>NOTE:</b> This interface is a special purpose interface, mainly for
* internal use within the framework. It is recommended to implement the plain
* {@link BeanPostProcessor} interface as far as possible.
* {@link BeanPostProcessor} interface as far as possible, or to derive from
* {@link InstantiationAwareBeanPostProcessorAdapter} in order to be shielded
* from extensions to this interface.
*
* @author Juergen Hoeller
* @author Rod Johnson
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -103,14 +103,6 @@ public abstract class AbstractBeanDefinitionReader implements BeanDefinitionRead
}
/**
* Return the bean factory to register the bean definitions with.
* <p>The factory is exposed through the BeanDefinitionRegistry interface,
* encapsulating the methods that are relevant for bean definition handling.
* @deprecated as of Spring Framework 5.3.15 in favor of {@link #getRegistry()},
* to be removed in Spring Framework 6.0
*/
@Deprecated
public final BeanDefinitionRegistry getBeanFactory() {
return this.registry;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,15 +22,15 @@ import org.springframework.core.io.ResourceLoader;
import org.springframework.lang.Nullable;
/**
* Simple interface for bean definition readers that specifies load methods with
* {@link Resource} and {@link String} location parameters.
* Simple interface for bean definition readers.
* Specifies load methods with Resource and String location parameters.
*
* <p>Concrete bean definition readers can of course add additional
* load and register methods for bean definitions, specific to
* their bean definition format.
*
* <p>Note that a bean definition reader does not have to implement
* this interface. It only serves as a suggestion for bean definition
* this interface. It only serves as suggestion for bean definition
* readers that want to follow standard naming conventions.
*
* @author Juergen Hoeller
@@ -41,14 +41,14 @@ public interface BeanDefinitionReader {
/**
* Return the bean factory to register the bean definitions with.
* <p>The factory is exposed through the {@link BeanDefinitionRegistry} interface,
* <p>The factory is exposed through the BeanDefinitionRegistry interface,
* encapsulating the methods that are relevant for bean definition handling.
*/
BeanDefinitionRegistry getRegistry();
/**
* Return the {@link ResourceLoader} to use for resource locations.
* <p>Can be checked for the {@code ResourcePatternResolver} interface and cast
* Return the resource loader to use for resource locations.
* Can be checked for the <b>ResourcePatternResolver</b> interface and cast
* accordingly, for loading multiple resources for a given resource pattern.
* <p>A {@code null} return value suggests that absolute resource loading
* is not available for this bean definition reader.
@@ -56,10 +56,10 @@ public interface BeanDefinitionReader {
* from within a bean definition resource, for example via the "import"
* tag in XML bean definitions. It is recommended, however, to apply
* such imports relative to the defining resource; only explicit full
* resource locations will trigger absolute path based resource loading.
* resource locations will trigger absolute resource loading.
* <p>There is also a {@code loadBeanDefinitions(String)} method available,
* for loading bean definitions from a resource location (or location pattern).
* This is a convenience to avoid explicit {@code ResourceLoader} handling.
* This is a convenience to avoid explicit ResourceLoader handling.
* @see #loadBeanDefinitions(String)
* @see org.springframework.core.io.support.ResourcePatternResolver
*/
@@ -70,13 +70,13 @@ public interface BeanDefinitionReader {
* Return the class loader to use for bean classes.
* <p>{@code null} suggests to not load bean classes eagerly
* but rather to just register bean definitions with class names,
* with the corresponding classes to be resolved later (or never).
* with the corresponding Classes to be resolved later (or never).
*/
@Nullable
ClassLoader getBeanClassLoader();
/**
* Return the {@link BeanNameGenerator} to use for anonymous beans
* Return the BeanNameGenerator to use for anonymous beans
* (without explicit bean name specified).
*/
BeanNameGenerator getBeanNameGenerator();
@@ -101,10 +101,9 @@ public interface BeanDefinitionReader {
/**
* Load bean definitions from the specified resource location.
* <p>The location can also be a location pattern, provided that the
* {@link ResourceLoader} of this bean definition reader is a
* {@code ResourcePatternResolver}.
* @param location the resource location, to be loaded with the {@code ResourceLoader}
* (or {@code ResourcePatternResolver}) of this bean definition reader
* ResourceLoader of this bean definition reader is a ResourcePatternResolver.
* @param location the resource location, to be loaded with the ResourceLoader
* (or ResourcePatternResolver) of this bean definition reader
* @return the number of bean definitions found
* @throws BeanDefinitionStoreException in case of loading or parsing errors
* @see #getResourceLoader()
@@ -115,8 +114,8 @@ public interface BeanDefinitionReader {
/**
* Load bean definitions from the specified resource locations.
* @param locations the resource locations, to be loaded with the {@code ResourceLoader}
* (or {@code ResourcePatternResolver}) of this bean definition reader
* @param locations the resource locations, to be loaded with the ResourceLoader
* (or ResourcePatternResolver) of this bean definition reader
* @return the number of bean definitions found
* @throws BeanDefinitionStoreException in case of loading or parsing errors
*/
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -730,23 +730,14 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
public <A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType)
throws NoSuchBeanDefinitionException {
return findAnnotationOnBean(beanName, annotationType, true);
}
@Override
@Nullable
public <A extends Annotation> A findAnnotationOnBean(
String beanName, Class<A> annotationType, boolean allowFactoryBeanInit)
throws NoSuchBeanDefinitionException {
return findMergedAnnotationOnBean(beanName, annotationType, allowFactoryBeanInit)
return findMergedAnnotationOnBean(beanName, annotationType)
.synthesize(MergedAnnotation::isPresent).orElse(null);
}
private <A extends Annotation> MergedAnnotation<A> findMergedAnnotationOnBean(
String beanName, Class<A> annotationType, boolean allowFactoryBeanInit) {
String beanName, Class<A> annotationType) {
Class<?> beanType = getType(beanName, allowFactoryBeanInit);
Class<?> beanType = getType(beanName);
if (beanType != null) {
MergedAnnotation<A> annotation =
MergedAnnotations.from(beanType, SearchStrategy.TYPE_HIERARCHY).get(annotationType);
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -459,16 +459,7 @@ public class StaticListableBeanFactory implements ListableBeanFactory {
public <A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType)
throws NoSuchBeanDefinitionException {
return findAnnotationOnBean(beanName, annotationType, true);
}
@Override
@Nullable
public <A extends Annotation> A findAnnotationOnBean(
String beanName, Class<A> annotationType, boolean allowFactoryBeanInit)
throws NoSuchBeanDefinitionException {
Class<?> beanType = getType(beanName, allowFactoryBeanInit);
Class<?> beanType = getType(beanName);
return (beanType != null ? AnnotatedElementUtils.findMergedAnnotation(beanType, annotationType) : null);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,7 +46,7 @@ public class BeanWrapperEnumTests {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("customEnum", null);
assertThat(gb.getCustomEnum()).isNull();
assertThat(gb.getCustomEnum()).isEqualTo(null);
}
@Test
@@ -54,7 +54,7 @@ public class BeanWrapperEnumTests {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("customEnum", "");
assertThat(gb.getCustomEnum()).isNull();
assertThat(gb.getCustomEnum()).isEqualTo(null);
}
@Test
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -433,7 +433,7 @@ class DefaultListableBeanFactoryTests {
assertThat(lbf.isTypeMatch("x1", Object.class)).isTrue();
assertThat(lbf.isTypeMatch("&x1", Object.class)).isFalse();
assertThat(lbf.getType("x1")).isEqualTo(TestBean.class);
assertThat(lbf.getType("&x1")).isNull();
assertThat(lbf.getType("&x1")).isEqualTo(null);
assertThat(TestBeanFactory.initialized).isFalse();
lbf.registerAlias("x1", "x2");
@@ -2622,8 +2622,8 @@ class DefaultListableBeanFactoryTests {
void containsBeanReturnsTrueEvenForAbstractBeanDefinition() {
lbf.registerBeanDefinition("abs", BeanDefinitionBuilder
.rootBeanDefinition(TestBean.class).setAbstract(true).getBeanDefinition());
assertThat(lbf.containsBean("abs")).isTrue();
assertThat(lbf.containsBean("bogus")).isFalse();
assertThat(lbf.containsBean("abs")).isEqualTo(true);
assertThat(lbf.containsBean("bogus")).isEqualTo(false);
}
@Test
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -111,7 +111,7 @@ public class PropertyResourceConfigurerTests {
assertThat(tb1.getAge()).isEqualTo(99);
assertThat(tb2.getAge()).isEqualTo(99);
assertThat(tb1.getName()).isNull();
assertThat(tb1.getName()).isEqualTo(null);
assertThat(tb2.getName()).isEqualTo("test");
}
@@ -310,7 +310,7 @@ public class PropertyResourceConfigurerTests {
TestBean tb2 = (TestBean) factory.getBean("tb2");
assertThat(tb1.getAge()).isEqualTo(99);
assertThat(tb2.getAge()).isEqualTo(99);
assertThat(tb1.getName()).isNull();
assertThat(tb1.getName()).isEqualTo(null);
assertThat(tb2.getName()).isEqualTo("test");
}
@@ -423,7 +423,7 @@ public class PropertyResourceConfigurerTests {
TestBean inner1 = (TestBean) tb2.getSomeMap().get("key3");
TestBean inner2 = (TestBean) tb2.getSomeMap().get("mykey4");
assertThat(inner1.getAge()).isEqualTo(0);
assertThat(inner1.getName()).isNull();
assertThat(inner1.getName()).isEqualTo(null);
assertThat(inner1.getCountry()).isEqualTo(System.getProperty("os.name"));
assertThat(inner2.getAge()).isEqualTo(98);
assertThat(inner2.getName()).isEqualTo("namemyvarmyvar${");
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -449,7 +449,7 @@ public class CallbacksSecurityTests {
public Object run() {
// sanity check
assertThat(getCurrentSubjectName()).isEqualTo("user1");
assertThat(NonPrivilegedBean.destroyed).isFalse();
assertThat(NonPrivilegedBean.destroyed).isEqualTo(false);
beanFactory.getBean("trusted-spring-callbacks");
beanFactory.getBean("trusted-custom-init-destroy");
@@ -465,7 +465,7 @@ public class CallbacksSecurityTests {
beanFactory.getBean("trusted-working-property-injection");
beanFactory.destroySingletons();
assertThat(NonPrivilegedBean.destroyed).isTrue();
assertThat(NonPrivilegedBean.destroyed).isEqualTo(true);
return null;
}
}, provider.getAccessControlContext());
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -100,17 +100,17 @@ public class FactoryMethodTests {
FactoryMethods fm = (FactoryMethods) xbf.getBean("fullWithNull");
assertThat(fm.getNum()).isEqualTo(27);
assertThat(fm.getName()).isNull();
assertThat(fm.getName()).isEqualTo(null);
assertThat(fm.getTestBean().getName()).isEqualTo("Juergen");
fm = (FactoryMethods) xbf.getBean("fullWithGenericNull");
assertThat(fm.getNum()).isEqualTo(27);
assertThat(fm.getName()).isNull();
assertThat(fm.getName()).isEqualTo(null);
assertThat(fm.getTestBean().getName()).isEqualTo("Juergen");
fm = (FactoryMethods) xbf.getBean("fullWithNamedNull");
assertThat(fm.getNum()).isEqualTo(27);
assertThat(fm.getName()).isNull();
assertThat(fm.getName()).isEqualTo(null);
assertThat(fm.getTestBean().getName()).isEqualTo("Juergen");
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -342,7 +342,7 @@ public class UtilNamespaceHandlerTests {
public void testLoadProperties() {
Properties props = (Properties) this.beanFactory.getBean("myProperties");
assertThat(props.get("foo")).as("Incorrect property value").isEqualTo("bar");
assertThat(props.get("foo2")).as("Incorrect property value").isNull();
assertThat(props.get("foo2")).as("Incorrect property value").isEqualTo(null);
Properties props2 = (Properties) this.beanFactory.getBean("myProperties");
assertThat(props == props2).isTrue();
}
@@ -351,17 +351,17 @@ public class UtilNamespaceHandlerTests {
public void testScopedProperties() {
Properties props = (Properties) this.beanFactory.getBean("myScopedProperties");
assertThat(props.get("foo")).as("Incorrect property value").isEqualTo("bar");
assertThat(props.get("foo2")).as("Incorrect property value").isNull();
assertThat(props.get("foo2")).as("Incorrect property value").isEqualTo(null);
Properties props2 = (Properties) this.beanFactory.getBean("myScopedProperties");
assertThat(props.get("foo")).as("Incorrect property value").isEqualTo("bar");
assertThat(props.get("foo2")).as("Incorrect property value").isNull();
assertThat(props.get("foo2")).as("Incorrect property value").isEqualTo(null);
assertThat(props != props2).isTrue();
}
@Test
public void testLocalProperties() {
Properties props = (Properties) this.beanFactory.getBean("myLocalProperties");
assertThat(props.get("foo")).as("Incorrect property value").isNull();
assertThat(props.get("foo")).as("Incorrect property value").isEqualTo(null);
assertThat(props.get("foo2")).as("Incorrect property value").isEqualTo("bar2");
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -283,7 +283,7 @@ public class XmlBeanCollectionTests {
Iterator it = hasMap.getSet().iterator();
assertThat(it.next()).isEqualTo("bar");
assertThat(it.next()).isEqualTo(jenny);
assertThat(it.next()).isNull();
assertThat(it.next()).isEqualTo(null);
}
@Test
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -181,7 +181,7 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest
assertThat(beanNames.contains("aliasWithoutId3")).isFalse();
TestBean tb4 = (TestBean) getBeanFactory().getBean(TestBean.class.getName() + "#0");
assertThat(tb4.getName()).isNull();
assertThat(tb4.getName()).isEqualTo(null);
Map drs = getListableBeanFactory().getBeansOfType(DummyReferencer.class, false, false);
assertThat(drs.size()).isEqualTo(5);
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import java.util.function.Supplier;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.cache.annotation.AbstractCachingConfiguration;
import org.springframework.cache.annotation.CachingConfigurer;
import org.springframework.cache.interceptor.CacheResolver;
import org.springframework.cache.jcache.interceptor.DefaultJCacheOperationSource;
import org.springframework.cache.jcache.interceptor.JCacheOperationSource;
@@ -45,14 +46,11 @@ public abstract class AbstractJCacheConfiguration extends AbstractCachingConfigu
@Override
protected void useCachingConfigurer(CachingConfigurerSupplier cachingConfigurerSupplier) {
super.useCachingConfigurer(cachingConfigurerSupplier);
this.exceptionCacheResolver = cachingConfigurerSupplier.adapt(config -> {
if (config instanceof JCacheConfigurer) {
return ((JCacheConfigurer) config).exceptionCacheResolver();
}
return null;
});
protected void useCachingConfigurer(CachingConfigurer config) {
super.useCachingConfigurer(config);
if (config instanceof JCacheConfigurer) {
this.exceptionCacheResolver = ((JCacheConfigurer) config)::exceptionCacheResolver;
}
}
@Bean(name = "jCacheOperationSource")
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,7 +26,8 @@ import org.springframework.lang.Nullable;
* <p>To be implemented by classes annotated with
* {@link org.springframework.cache.annotation.EnableCaching} that wish
* or need to specify explicitly how exception caches are resolved for
* annotation-driven cache management.
* annotation-driven cache management. Consider extending {@link JCacheConfigurerSupport},
* which provides a stub implementation of all interface methods.
*
* <p>See {@link org.springframework.cache.annotation.EnableCaching} for
* general examples and context; see {@link #exceptionCacheResolver()} for
@@ -35,6 +36,7 @@ import org.springframework.lang.Nullable;
* @author Stephane Nicoll
* @since 4.1
* @see CachingConfigurer
* @see JCacheConfigurerSupport
* @see org.springframework.cache.annotation.EnableCaching
*/
public interface JCacheConfigurer extends CachingConfigurer {
@@ -58,8 +60,6 @@ public interface JCacheConfigurer extends CachingConfigurer {
* See {@link org.springframework.cache.annotation.EnableCaching} for more complete examples.
*/
@Nullable
default CacheResolver exceptionCacheResolver() {
return null;
}
CacheResolver exceptionCacheResolver();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -79,7 +79,7 @@ public abstract class AbstractFallbackJCacheOperationSource implements JCacheOpe
@Nullable
private JCacheOperation<?> computeCacheOperation(Method method, @Nullable Class<?> targetClass) {
// Don't allow non-public methods, as configured.
// Don't allow no-public methods as required.
if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) {
return null;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,8 +39,6 @@ import org.springframework.lang.Nullable;
* Subclass of Quartz's {@link JobStoreCMT} class that delegates to a Spring-managed
* {@link DataSource} instead of using a Quartz-managed JDBC connection pool.
* This JobStore will be used if SchedulerFactoryBean's "dataSource" property is set.
* You may also configure it explicitly, possibly as a custom subclass of this
* {@code LocalDataSourceJobStore} or as an equivalent {@code JobStoreCMT} variant.
*
* <p>Supports both transactional and non-transactional DataSource access.
* With a non-XA DataSource and local Spring transactions, a single DataSource
@@ -60,8 +58,6 @@ import org.springframework.lang.Nullable;
* @since 1.1
* @see SchedulerFactoryBean#setDataSource
* @see SchedulerFactoryBean#setNonTransactionalDataSource
* @see SchedulerFactoryBean#getConfigTimeDataSource()
* @see SchedulerFactoryBean#getConfigTimeNonTransactionalDataSource()
* @see org.springframework.jdbc.datasource.DataSourceUtils#doGetConnection
* @see org.springframework.jdbc.datasource.DataSourceUtils#releaseConnection
*/
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -310,11 +310,9 @@ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBe
/**
* Set the default {@link DataSource} to be used by the Scheduler.
* If set, this will override corresponding settings in Quartz properties.
* <p>Note: If this is set, the Quartz settings should not define
* a job store "dataSource" to avoid meaningless double configuration.
* Also, do not define a "org.quartz.jobStore.class" property at all.
* (You may explicitly define Spring's {@link LocalDataSourceJobStore}
* but that's the default when using this method anyway.)
* <p>A Spring-specific subclass of Quartz' JobStoreCMT will be used.
* It is therefore strongly recommended to perform all operations on
* the Scheduler within Spring-managed (or plain JTA) transactions.
@@ -572,7 +570,7 @@ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBe
CollectionUtils.mergePropertiesIntoMap(this.quartzProperties, mergedProps);
if (this.dataSource != null) {
mergedProps.putIfAbsent(StdSchedulerFactory.PROP_JOB_STORE_CLASS, LocalDataSourceJobStore.class.getName());
mergedProps.setProperty(StdSchedulerFactory.PROP_JOB_STORE_CLASS, LocalDataSourceJobStore.class.getName());
}
// Determine scheduler name across local settings and Quartz properties...
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -106,7 +106,7 @@ class CaffeineCacheTests extends AbstractValueAdaptingCacheTests<CaffeineCache>
Cache.ValueWrapper wrapper = cache.putIfAbsent(key, "anotherValue");
// A value is set but is 'null'
assertThat(wrapper).isNotNull();
assertThat(wrapper.get()).isNull();
assertThat(wrapper.get()).isEqualTo(null);
// not changed
assertThat(cache.get(key).get()).isEqualTo(value);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@ import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachingConfigurer;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.cache.interceptor.SimpleKeyGenerator;
@@ -104,7 +104,7 @@ public class JCacheEhCacheAnnotationTests extends AbstractCacheAnnotationTests {
@Configuration
@EnableCaching
static class EnableCachingConfig implements CachingConfigurer {
static class EnableCachingConfig extends CachingConfigurerSupport {
@Autowired
CachingProvider cachingProvider;
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -180,7 +180,7 @@ public class JCacheJavaConfigTests extends AbstractJCacheAnnotationTests {
@Configuration
@EnableCaching
public static class EmptyConfigSupportConfig implements JCacheConfigurer {
public static class EmptyConfigSupportConfig extends JCacheConfigurerSupport {
@Bean
public CacheManager cm() {
return new NoOpCacheManager();
@@ -190,7 +190,7 @@ public class JCacheJavaConfigTests extends AbstractJCacheAnnotationTests {
@Configuration
@EnableCaching
static class FullCachingConfigSupport implements JCacheConfigurer {
static class FullCachingConfigSupport extends JCacheConfigurerSupport {
@Override
@Bean
@@ -220,7 +220,7 @@ public class JCacheJavaConfigTests extends AbstractJCacheAnnotationTests {
@Configuration
@EnableCaching
static class NoExceptionCacheResolverConfig implements JCacheConfigurer {
static class NoExceptionCacheResolverConfig extends JCacheConfigurerSupport {
@Override
@Bean
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@ import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.CacheErrorHandler;
import org.springframework.cache.interceptor.SimpleKeyGenerator;
import org.springframework.cache.jcache.config.JCacheConfigurer;
import org.springframework.cache.jcache.config.JCacheConfigurerSupport;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -141,7 +141,7 @@ public class JCacheErrorHandlerTests {
@Configuration
@EnableCaching
static class Config implements JCacheConfigurer {
static class Config extends JCacheConfigurerSupport {
@Bean
@Override
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@ import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.cache.interceptor.SimpleKey;
import org.springframework.cache.interceptor.SimpleKeyGenerator;
import org.springframework.cache.jcache.config.JCacheConfigurer;
import org.springframework.cache.jcache.config.JCacheConfigurerSupport;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -97,7 +97,7 @@ public class JCacheKeyGeneratorTests {
@Configuration
@EnableCaching
static class Config implements JCacheConfigurer {
static class Config extends JCacheConfigurerSupport {
@Bean
@Override
@@ -151,7 +151,7 @@ public class JCacheKeyGeneratorTests {
@Override
public Object generate(Object target, Method method, Object... params) {
assertThat(Arrays.equals(expectedParams, params)).as("Unexpected parameters: expected: "
+ Arrays.toString(this.expectedParams) + " but got: " + Arrays.toString(params)).isTrue();
+ Arrays.toString(this.expectedParams) + " but got: " + Arrays.toString(params)).isTrue();
return new SimpleKey(params);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@ package org.springframework.scheduling.quartz;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import javax.sql.DataSource;
@@ -31,7 +30,6 @@ import org.quartz.SchedulerContext;
import org.quartz.SchedulerFactory;
import org.quartz.impl.JobDetailImpl;
import org.quartz.impl.SchedulerRepository;
import org.quartz.impl.jdbcjobstore.JobStoreTX;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
@@ -42,8 +40,6 @@ import org.springframework.context.support.StaticApplicationContext;
import org.springframework.core.task.TaskExecutor;
import org.springframework.core.testfixture.EnabledForTestGroups;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@@ -61,10 +57,10 @@ import static org.springframework.core.testfixture.TestGroup.LONG_RUNNING;
* @author Sam Brannen
* @since 20.02.2004
*/
class QuartzSupportTests {
public class QuartzSupportTests {
@Test
void schedulerFactoryBeanWithApplicationContext() throws Exception {
public void schedulerFactoryBeanWithApplicationContext() throws Exception {
TestBean tb = new TestBean("tb", 99);
StaticApplicationContext ac = new StaticApplicationContext();
@@ -101,7 +97,7 @@ class QuartzSupportTests {
@Test
@EnabledForTestGroups(LONG_RUNNING)
void schedulerWithTaskExecutor() throws Exception {
public void schedulerWithTaskExecutor() throws Exception {
CountingTaskExecutor taskExecutor = new CountingTaskExecutor();
DummyJob.count = 0;
@@ -134,7 +130,7 @@ class QuartzSupportTests {
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
void jobDetailWithRunnableInsteadOfJob() {
public void jobDetailWithRunnableInsteadOfJob() {
JobDetailImpl jobDetail = new JobDetailImpl();
assertThatIllegalArgumentException().isThrownBy(() ->
jobDetail.setJobClass((Class) DummyRunnable.class));
@@ -142,7 +138,7 @@ class QuartzSupportTests {
@Test
@EnabledForTestGroups(LONG_RUNNING)
void schedulerWithQuartzJobBean() throws Exception {
public void schedulerWithQuartzJobBean() throws Exception {
DummyJob.param = 0;
DummyJob.count = 0;
@@ -175,7 +171,7 @@ class QuartzSupportTests {
@Test
@EnabledForTestGroups(LONG_RUNNING)
void schedulerWithSpringBeanJobFactory() throws Exception {
public void schedulerWithSpringBeanJobFactory() throws Exception {
DummyJob.param = 0;
DummyJob.count = 0;
@@ -210,7 +206,7 @@ class QuartzSupportTests {
@Test
@EnabledForTestGroups(LONG_RUNNING)
void schedulerWithSpringBeanJobFactoryAndParamMismatchNotIgnored() throws Exception {
public void schedulerWithSpringBeanJobFactoryAndParamMismatchNotIgnored() throws Exception {
DummyJob.param = 0;
DummyJob.count = 0;
@@ -246,7 +242,7 @@ class QuartzSupportTests {
@Test
@EnabledForTestGroups(LONG_RUNNING)
void schedulerWithSpringBeanJobFactoryAndQuartzJobBean() throws Exception {
public void schedulerWithSpringBeanJobFactoryAndQuartzJobBean() throws Exception {
DummyJobBean.param = 0;
DummyJobBean.count = 0;
@@ -280,7 +276,7 @@ class QuartzSupportTests {
@Test
@EnabledForTestGroups(LONG_RUNNING)
void schedulerWithSpringBeanJobFactoryAndJobSchedulingData() throws Exception {
public void schedulerWithSpringBeanJobFactoryAndJobSchedulingData() throws Exception {
DummyJob.param = 0;
DummyJob.count = 0;
@@ -298,7 +294,7 @@ class QuartzSupportTests {
}
@Test // SPR-772
void multipleSchedulers() throws Exception {
public void multipleSchedulers() throws Exception {
try (ClassPathXmlApplicationContext ctx = context("multipleSchedulers.xml")) {
Scheduler scheduler1 = (Scheduler) ctx.getBean("scheduler1");
Scheduler scheduler2 = (Scheduler) ctx.getBean("scheduler2");
@@ -309,7 +305,7 @@ class QuartzSupportTests {
}
@Test // SPR-16884
void multipleSchedulersWithQuartzProperties() throws Exception {
public void multipleSchedulersWithQuartzProperties() throws Exception {
try (ClassPathXmlApplicationContext ctx = context("multipleSchedulersWithQuartzProperties.xml")) {
Scheduler scheduler1 = (Scheduler) ctx.getBean("scheduler1");
Scheduler scheduler2 = (Scheduler) ctx.getBean("scheduler2");
@@ -321,13 +317,12 @@ class QuartzSupportTests {
@Test
@EnabledForTestGroups(LONG_RUNNING)
void twoAnonymousMethodInvokingJobDetailFactoryBeans() throws Exception {
public void twoAnonymousMethodInvokingJobDetailFactoryBeans() throws Exception {
Thread.sleep(3000);
try (ClassPathXmlApplicationContext ctx = context("multipleAnonymousMethodInvokingJobDetailFB.xml")) {
QuartzTestBean exportService = (QuartzTestBean) ctx.getBean("exportService");
QuartzTestBean importService = (QuartzTestBean) ctx.getBean("importService");
Thread.sleep(400);
assertThat(exportService.getImportCount()).as("doImport called exportService").isEqualTo(0);
assertThat(exportService.getExportCount()).as("doExport not called on exportService").isEqualTo(2);
assertThat(importService.getImportCount()).as("doImport not called on importService").isEqualTo(2);
@@ -337,13 +332,12 @@ class QuartzSupportTests {
@Test
@EnabledForTestGroups(LONG_RUNNING)
void schedulerAccessorBean() throws Exception {
public void schedulerAccessorBean() throws Exception {
Thread.sleep(3000);
try (ClassPathXmlApplicationContext ctx = context("schedulerAccessorBean.xml")) {
QuartzTestBean exportService = (QuartzTestBean) ctx.getBean("exportService");
QuartzTestBean importService = (QuartzTestBean) ctx.getBean("importService");
Thread.sleep(400);
assertThat(exportService.getImportCount()).as("doImport called exportService").isEqualTo(0);
assertThat(exportService.getExportCount()).as("doExport not called on exportService").isEqualTo(2);
assertThat(importService.getImportCount()).as("doImport not called on importService").isEqualTo(2);
@@ -353,7 +347,7 @@ class QuartzSupportTests {
@Test
@SuppressWarnings("resource")
void schedulerAutoStartsOnContextRefreshedEventByDefault() throws Exception {
public void schedulerAutoStartsOnContextRefreshedEventByDefault() throws Exception {
StaticApplicationContext context = new StaticApplicationContext();
context.registerBeanDefinition("scheduler", new RootBeanDefinition(SchedulerFactoryBean.class));
Scheduler bean = context.getBean("scheduler", Scheduler.class);
@@ -364,7 +358,7 @@ class QuartzSupportTests {
@Test
@SuppressWarnings("resource")
void schedulerAutoStartupFalse() throws Exception {
public void schedulerAutoStartupFalse() throws Exception {
StaticApplicationContext context = new StaticApplicationContext();
BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(SchedulerFactoryBean.class)
.addPropertyValue("autoStartup", false).getBeanDefinition();
@@ -376,7 +370,7 @@ class QuartzSupportTests {
}
@Test
void schedulerRepositoryExposure() throws Exception {
public void schedulerRepositoryExposure() throws Exception {
try (ClassPathXmlApplicationContext ctx = context("schedulerRepositoryExposure.xml")) {
assertThat(ctx.getBean("scheduler")).isSameAs(SchedulerRepository.getInstance().lookup("myScheduler"));
}
@@ -387,7 +381,7 @@ class QuartzSupportTests {
* TODO: Against Quartz 2.2, this test's job doesn't actually execute anymore...
*/
@Test
void schedulerWithHsqlDataSource() throws Exception {
public void schedulerWithHsqlDataSource() throws Exception {
DummyJob.param = 0;
DummyJob.count = 0;
@@ -402,36 +396,12 @@ class QuartzSupportTests {
}
}
@Test
@SuppressWarnings("resource")
void schedulerFactoryBeanWithCustomJobStore() throws Exception {
StaticApplicationContext context = new StaticApplicationContext();
String dbName = "mydb";
EmbeddedDatabase database = new EmbeddedDatabaseBuilder().setName(dbName).build();
Properties properties = new Properties();
properties.setProperty("org.quartz.jobStore.class", JobStoreTX.class.getName());
properties.setProperty("org.quartz.jobStore.dataSource", dbName);
BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(SchedulerFactoryBean.class)
.addPropertyValue("autoStartup", false)
.addPropertyValue("dataSource", database)
.addPropertyValue("quartzProperties", properties)
.getBeanDefinition();
context.registerBeanDefinition("scheduler", beanDefinition);
Scheduler scheduler = context.getBean(Scheduler.class);
assertThat(scheduler.getMetaData().getJobStoreClass()).isEqualTo(JobStoreTX.class);
}
private ClassPathXmlApplicationContext context(String path) {
return new ClassPathXmlApplicationContext(path, getClass());
}
private static class CountingTaskExecutor implements TaskExecutor {
public static class CountingTaskExecutor implements TaskExecutor {
private int count;
@@ -443,14 +413,12 @@ class QuartzSupportTests {
}
private static class DummyJob implements Job {
public static class DummyJob implements Job {
private static int param;
private static int count;
@SuppressWarnings("unused")
// Must be public
public void setParam(int value) {
if (param > 0) {
throw new IllegalStateException("Param already set");
@@ -465,13 +433,12 @@ class QuartzSupportTests {
}
private static class DummyJobBean extends QuartzJobBean {
public static class DummyJobBean extends QuartzJobBean {
private static int param;
private static int count;
@SuppressWarnings("unused")
public void setParam(int value) {
if (param > 0) {
throw new IllegalStateException("Param already set");
@@ -486,7 +453,7 @@ class QuartzSupportTests {
}
private static class DummyRunnable implements Runnable {
public static class DummyRunnable implements Runnable {
@Override
public void run() {
@@ -19,7 +19,7 @@
<property name="targetMethod" value="doExport"/>
</bean>
</property>
<property name="repeatInterval" value="200"/>
<property name="repeatInterval" value="1000"/>
<property name="repeatCount" value="1"/>
</bean>
@@ -30,7 +30,7 @@
<property name="targetMethod" value="doImport"/>
</bean>
</property>
<property name="repeatInterval" value="200"/>
<property name="repeatInterval" value="1000"/>
<property name="repeatCount" value="1"/>
</bean>
@@ -21,7 +21,7 @@
<property name="targetMethod" value="doExport"/>
</bean>
</property>
<property name="repeatInterval" value="200"/>
<property name="repeatInterval" value="1000"/>
<property name="repeatCount" value="1"/>
</bean>
@@ -32,7 +32,7 @@
<property name="targetMethod" value="doImport"/>
</bean>
</property>
<property name="repeatInterval" value="200"/>
<property name="repeatInterval" value="1000"/>
<property name="repeatCount" value="1"/>
</bean>
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,12 +16,9 @@
package org.springframework.cache.annotation;
import java.util.List;
import java.util.function.Function;
import java.util.Collection;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.cache.interceptor.CacheErrorHandler;
@@ -33,7 +30,6 @@ import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.function.SingletonSupplier;
/**
* Abstract base {@code @Configuration} class providing common structure
@@ -67,67 +63,36 @@ public abstract class AbstractCachingConfiguration implements ImportAware {
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
this.enableCaching = AnnotationAttributes.fromMap(
importMetadata.getAnnotationAttributes(EnableCaching.class.getName()));
importMetadata.getAnnotationAttributes(EnableCaching.class.getName(), false));
if (this.enableCaching == null) {
throw new IllegalArgumentException(
"@EnableCaching is not present on importing class " + importMetadata.getClassName());
}
}
@Autowired
void setConfigurers(ObjectProvider<CachingConfigurer> configurers) {
Supplier<CachingConfigurer> configurer = () -> {
List<CachingConfigurer> candidates = configurers.stream().collect(Collectors.toList());
if (CollectionUtils.isEmpty(candidates)) {
return null;
}
if (candidates.size() > 1) {
throw new IllegalStateException(candidates.size() + " implementations of " +
"CachingConfigurer were found when only 1 was expected. " +
"Refactor the configuration such that CachingConfigurer is " +
"implemented only once or not at all.");
}
return candidates.get(0);
};
useCachingConfigurer(new CachingConfigurerSupplier(configurer));
@Autowired(required = false)
void setConfigurers(Collection<CachingConfigurer> configurers) {
if (CollectionUtils.isEmpty(configurers)) {
return;
}
if (configurers.size() > 1) {
throw new IllegalStateException(configurers.size() + " implementations of " +
"CachingConfigurer were found when only 1 was expected. " +
"Refactor the configuration such that CachingConfigurer is " +
"implemented only once or not at all.");
}
CachingConfigurer configurer = configurers.iterator().next();
useCachingConfigurer(configurer);
}
/**
* Extract the configuration from the nominated {@link CachingConfigurer}.
*/
protected void useCachingConfigurer(CachingConfigurerSupplier cachingConfigurerSupplier) {
this.cacheManager = cachingConfigurerSupplier.adapt(CachingConfigurer::cacheManager);
this.cacheResolver = cachingConfigurerSupplier.adapt(CachingConfigurer::cacheResolver);
this.keyGenerator = cachingConfigurerSupplier.adapt(CachingConfigurer::keyGenerator);
this.errorHandler = cachingConfigurerSupplier.adapt(CachingConfigurer::errorHandler);
}
protected static class CachingConfigurerSupplier {
private final Supplier<CachingConfigurer> supplier;
public CachingConfigurerSupplier(Supplier<CachingConfigurer> supplier) {
this.supplier = SingletonSupplier.of(supplier);
}
/**
* Adapt the {@link CachingConfigurer} supplier to another supplier
* provided by the specified mapping function. If the underlying
* {@link CachingConfigurer} is {@code null}, {@code null} is returned
* and the mapping function is not invoked.
* @param provider the provider to use to adapt the supplier
* @param <T> the type of the supplier
* @return another supplier mapped by the specified function
*/
@Nullable
public <T> Supplier<T> adapt(Function<CachingConfigurer, T> provider) {
return () -> {
CachingConfigurer cachingConfigurer = this.supplier.get();
return (cachingConfigurer != null ? provider.apply(cachingConfigurer) : null);
};
}
protected void useCachingConfigurer(CachingConfigurer config) {
this.cacheManager = config::cacheManager;
this.cacheResolver = config::cacheResolver;
this.keyGenerator = config::keyGenerator;
this.errorHandler = config::errorHandler;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,7 +26,8 @@ import org.springframework.lang.Nullable;
* Interface to be implemented by @{@link org.springframework.context.annotation.Configuration
* Configuration} classes annotated with @{@link EnableCaching} that wish or need to
* specify explicitly how caches are resolved and how keys are generated for annotation-driven
* cache management.
* cache management. Consider extending {@link CachingConfigurerSupport}, which provides a
* stub implementation of all interface methods.
*
* <p>See @{@link EnableCaching} for general examples and context; see
* {@link #cacheManager()}, {@link #cacheResolver()} and {@link #keyGenerator()}
@@ -36,6 +37,7 @@ import org.springframework.lang.Nullable;
* @author Stephane Nicoll
* @since 3.1
* @see EnableCaching
* @see CachingConfigurerSupport
*/
public interface CachingConfigurer {
@@ -62,9 +64,7 @@ public interface CachingConfigurer {
* See @{@link EnableCaching} for more complete examples.
*/
@Nullable
default CacheManager cacheManager() {
return null;
}
CacheManager cacheManager();
/**
* Return the {@link CacheResolver} bean to use to resolve regular caches for
@@ -89,9 +89,7 @@ public interface CachingConfigurer {
* See {@link EnableCaching} for more complete examples.
*/
@Nullable
default CacheResolver cacheResolver() {
return null;
}
CacheResolver cacheResolver();
/**
* Return the key generator bean to use for annotation-driven cache management.
@@ -112,9 +110,7 @@ public interface CachingConfigurer {
* See @{@link EnableCaching} for more complete examples.
*/
@Nullable
default KeyGenerator keyGenerator() {
return null;
}
KeyGenerator keyGenerator();
/**
* Return the {@link CacheErrorHandler} to use to handle cache-related errors.
@@ -137,8 +133,6 @@ public interface CachingConfigurer {
* See @{@link EnableCaching} for more complete examples.
*/
@Nullable
default CacheErrorHandler errorHandler() {
return null;
}
CacheErrorHandler errorHandler();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -124,7 +124,7 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera
@Nullable
private Collection<CacheOperation> computeCacheOperations(Method method, @Nullable Class<?> targetClass) {
// Don't allow non-public methods, as configured.
// Don't allow no-public methods as required.
if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) {
return null;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,10 +47,9 @@ import org.springframework.util.StringUtils;
*
* <p>If the annotation's value doesn't indicate a bean name, an appropriate
* name will be built based on the short name of the class (with the first
* letter lower-cased), unless the two first letters are uppercase. For example:
* letter lower-cased). For example:
*
* <pre class="code">com.xyz.FooServiceImpl -&gt; fooServiceImpl</pre>
* <pre class="code">com.xyz.URLFooServiceImpl -&gt; URLFooServiceImpl</pre>
*
* @author Juergen Hoeller
* @author Mark Fisher
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -282,7 +282,7 @@ public abstract class AnnotationConfigUtils {
@Nullable
static AnnotationAttributes attributesFor(AnnotatedTypeMetadata metadata, String annotationClassName) {
return AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(annotationClassName));
return AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(annotationClassName, false));
}
static Set<AnnotationAttributes> attributesForRepeatable(AnnotationMetadata metadata,
@@ -298,10 +298,10 @@ public abstract class AnnotationConfigUtils {
Set<AnnotationAttributes> result = new LinkedHashSet<>();
// Direct annotation present?
addAttributesIfNotNull(result, metadata.getAnnotationAttributes(annotationClassName));
addAttributesIfNotNull(result, metadata.getAnnotationAttributes(annotationClassName, false));
// Container annotation present?
Map<String, Object> container = metadata.getAnnotationAttributes(containerClassName);
Map<String, Object> container = metadata.getAnnotationAttributes(containerClassName, false);
if (container != null && container.containsKey("value")) {
for (Map<String, Object> containedAttributes : (Map<String, Object>[]) container.get("value")) {
addAttributesIfNotNull(result, containedAttributes);
@@ -343,7 +343,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
}
private InjectionMetadata findResourceMetadata(String beanName, Class<?> clazz, @Nullable PropertyValues pvs) {
private InjectionMetadata findResourceMetadata(String beanName, final Class<?> clazz, @Nullable PropertyValues pvs) {
// Fall back to class name as cache key, for backwards compatibility with custom callers.
String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
// Quick check on the concurrent map first, with minimal locking.
@@ -363,7 +363,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
return metadata;
}
private InjectionMetadata buildResourceMetadata(Class<?> clazz) {
private InjectionMetadata buildResourceMetadata(final Class<?> clazz) {
if (!AnnotationUtils.isCandidateClass(clazz, resourceAnnotationTypes)) {
return InjectionMetadata.EMPTY;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,10 +16,13 @@
package org.springframework.context.annotation;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
@@ -30,7 +33,12 @@ import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.filter.AbstractTypeHierarchyTraversingFilter;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.core.type.filter.AspectJTypeFilter;
import org.springframework.core.type.filter.AssignableTypeFilter;
import org.springframework.core.type.filter.RegexPatternTypeFilter;
import org.springframework.core.type.filter.TypeFilter;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
@@ -65,7 +73,7 @@ class ComponentScanAnnotationParser {
}
public Set<BeanDefinitionHolder> parse(AnnotationAttributes componentScan, String declaringClass) {
public Set<BeanDefinitionHolder> parse(AnnotationAttributes componentScan, final String declaringClass) {
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(this.registry,
componentScan.getBoolean("useDefaultFilters"), this.environment, this.resourceLoader);
@@ -85,17 +93,13 @@ class ComponentScanAnnotationParser {
scanner.setResourcePattern(componentScan.getString("resourcePattern"));
for (AnnotationAttributes includeFilterAttributes : componentScan.getAnnotationArray("includeFilters")) {
List<TypeFilter> typeFilters = TypeFilterUtils.createTypeFiltersFor(includeFilterAttributes, this.environment,
this.resourceLoader, this.registry);
for (TypeFilter typeFilter : typeFilters) {
for (AnnotationAttributes filter : componentScan.getAnnotationArray("includeFilters")) {
for (TypeFilter typeFilter : typeFiltersFor(filter)) {
scanner.addIncludeFilter(typeFilter);
}
}
for (AnnotationAttributes excludeFilterAttributes : componentScan.getAnnotationArray("excludeFilters")) {
List<TypeFilter> typeFilters = TypeFilterUtils.createTypeFiltersFor(excludeFilterAttributes, this.environment,
this.resourceLoader, this.registry);
for (TypeFilter typeFilter : typeFilters) {
for (AnnotationAttributes filter : componentScan.getAnnotationArray("excludeFilters")) {
for (TypeFilter typeFilter : typeFiltersFor(filter)) {
scanner.addExcludeFilter(typeFilter);
}
}
@@ -128,4 +132,49 @@ class ComponentScanAnnotationParser {
return scanner.doScan(StringUtils.toStringArray(basePackages));
}
private List<TypeFilter> typeFiltersFor(AnnotationAttributes filterAttributes) {
List<TypeFilter> typeFilters = new ArrayList<>();
FilterType filterType = filterAttributes.getEnum("type");
for (Class<?> filterClass : filterAttributes.getClassArray("classes")) {
switch (filterType) {
case ANNOTATION:
Assert.isAssignable(Annotation.class, filterClass,
"@ComponentScan ANNOTATION type filter requires an annotation type");
@SuppressWarnings("unchecked")
Class<Annotation> annotationType = (Class<Annotation>) filterClass;
typeFilters.add(new AnnotationTypeFilter(annotationType));
break;
case ASSIGNABLE_TYPE:
typeFilters.add(new AssignableTypeFilter(filterClass));
break;
case CUSTOM:
Assert.isAssignable(TypeFilter.class, filterClass,
"@ComponentScan CUSTOM type filter requires a TypeFilter implementation");
TypeFilter filter = ParserStrategyUtils.instantiateClass(filterClass, TypeFilter.class,
this.environment, this.resourceLoader, this.registry);
typeFilters.add(filter);
break;
default:
throw new IllegalArgumentException("Filter type not supported with Class value: " + filterType);
}
}
for (String expression : filterAttributes.getStringArray("pattern")) {
switch (filterType) {
case ASPECTJ:
typeFilters.add(new AspectJTypeFilter(expression, this.resourceLoader.getClassLoader()));
break;
case REGEX:
typeFilters.add(new RegexPatternTypeFilter(Pattern.compile(expression)));
break;
default:
throw new IllegalArgumentException("Filter type not supported with String pattern: " + filterType);
}
}
return typeFilters;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -453,8 +453,8 @@ class ConfigurationClassEnhancer {
* instance directly. If a FactoryBean instance is fetched through the container via &-dereferencing,
* it will not be proxied. This too is aligned with the way XML configuration works.
*/
private Object enhanceFactoryBean(Object factoryBean, Class<?> exposedType,
ConfigurableBeanFactory beanFactory, String beanName) {
private Object enhanceFactoryBean(final Object factoryBean, Class<?> exposedType,
final ConfigurableBeanFactory beanFactory, final String beanName) {
try {
Class<?> clazz = factoryBean.getClass();
@@ -489,8 +489,8 @@ class ConfigurationClassEnhancer {
return createCglibProxyForFactoryBean(factoryBean, beanFactory, beanName);
}
private Object createInterfaceProxyForFactoryBean(Object factoryBean, Class<?> interfaceType,
ConfigurableBeanFactory beanFactory, String beanName) {
private Object createInterfaceProxyForFactoryBean(final Object factoryBean, Class<?> interfaceType,
final ConfigurableBeanFactory beanFactory, final String beanName) {
return Proxy.newProxyInstance(
factoryBean.getClass().getClassLoader(), new Class<?>[] {interfaceType},
@@ -502,8 +502,8 @@ class ConfigurationClassEnhancer {
});
}
private Object createCglibProxyForFactoryBean(Object factoryBean,
ConfigurableBeanFactory beanFactory, String beanName) {
private Object createCglibProxyForFactoryBean(final Object factoryBean,
final ConfigurableBeanFactory beanFactory, final String beanName) {
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(factoryBean.getClass());
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,11 +47,6 @@ import java.lang.annotation.Target;
* or {@link javax.inject.Inject}: In that context, it leads to the creation of a
* lazy-resolution proxy for all affected dependencies, as an alternative to using
* {@link org.springframework.beans.factory.ObjectFactory} or {@link javax.inject.Provider}.
* Please note that such a lazy-resolution proxy will always be injected; if the target
* dependency does not exist, you will only be able to find out through an exception on
* invocation. As a consequence, such an injection point results in unintuitive behavior
* for optional dependencies. For a programmatic equivalent, allowing for lazy references
* with more sophistication, consider {@link org.springframework.beans.factory.ObjectProvider}.
*
* @author Chris Beams
* @author Juergen Hoeller
@@ -1,119 +0,0 @@
/*
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.context.annotation;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.core.type.filter.AspectJTypeFilter;
import org.springframework.core.type.filter.AssignableTypeFilter;
import org.springframework.core.type.filter.RegexPatternTypeFilter;
import org.springframework.core.type.filter.TypeFilter;
import org.springframework.util.Assert;
/**
* Collection of utilities for working with {@link ComponentScan @ComponentScan}
* {@linkplain ComponentScan.Filter type filters}.
*
* @author Chris Beams
* @author Juergen Hoeller
* @author Sam Brannen
* @since 5.3.13
* @see ComponentScan.Filter
* @see org.springframework.core.type.filter.TypeFilter
*/
public abstract class TypeFilterUtils {
/**
* Create {@linkplain TypeFilter type filters} from the supplied
* {@link AnnotationAttributes}, such as those sourced from
* {@link ComponentScan#includeFilters()} or {@link ComponentScan#excludeFilters()}.
* <p>Each {@link TypeFilter} will be instantiated using an appropriate
* constructor, with {@code BeanClassLoaderAware}, {@code BeanFactoryAware},
* {@code EnvironmentAware}, and {@code ResourceLoaderAware} contracts
* invoked if they are implemented by the type filter.
* @param filterAttributes {@code AnnotationAttributes} for a
* {@link ComponentScan.Filter @Filter} declaration
* @param environment the {@code Environment} to make available to filters
* @param resourceLoader the {@code ResourceLoader} to make available to filters
* @param registry the {@code BeanDefinitionRegistry} to make available to filters
* as a {@link org.springframework.beans.factory.BeanFactory} if applicable
* @return a list of instantiated and configured type filters
* @see TypeFilter
* @see AnnotationTypeFilter
* @see AssignableTypeFilter
* @see AspectJTypeFilter
* @see RegexPatternTypeFilter
* @see org.springframework.beans.factory.BeanClassLoaderAware
* @see org.springframework.beans.factory.BeanFactoryAware
* @see org.springframework.context.EnvironmentAware
* @see org.springframework.context.ResourceLoaderAware
*/
public static List<TypeFilter> createTypeFiltersFor(AnnotationAttributes filterAttributes, Environment environment,
ResourceLoader resourceLoader, BeanDefinitionRegistry registry) {
List<TypeFilter> typeFilters = new ArrayList<>();
FilterType filterType = filterAttributes.getEnum("type");
for (Class<?> filterClass : filterAttributes.getClassArray("classes")) {
switch (filterType) {
case ANNOTATION:
Assert.isAssignable(Annotation.class, filterClass,
"@ComponentScan ANNOTATION type filter requires an annotation type");
@SuppressWarnings("unchecked")
Class<Annotation> annotationType = (Class<Annotation>) filterClass;
typeFilters.add(new AnnotationTypeFilter(annotationType));
break;
case ASSIGNABLE_TYPE:
typeFilters.add(new AssignableTypeFilter(filterClass));
break;
case CUSTOM:
Assert.isAssignable(TypeFilter.class, filterClass,
"@ComponentScan CUSTOM type filter requires a TypeFilter implementation");
TypeFilter filter = ParserStrategyUtils.instantiateClass(filterClass, TypeFilter.class,
environment, resourceLoader, registry);
typeFilters.add(filter);
break;
default:
throw new IllegalArgumentException("Filter type not supported with Class value: " + filterType);
}
}
for (String expression : filterAttributes.getStringArray("pattern")) {
switch (filterType) {
case ASPECTJ:
typeFilters.add(new AspectJTypeFilter(expression, resourceLoader.getClassLoader()));
break;
case REGEX:
typeFilters.add(new RegexPatternTypeFilter(Pattern.compile(expression)));
break;
default:
throw new IllegalArgumentException("Filter type not supported with String pattern: " + filterType);
}
}
return typeFilters;
}
}
@@ -75,7 +75,7 @@ public abstract class CachedExpressionEvaluator {
/**
* Return the {@link Expression} for the specified SpEL value
* <p>{@link #parseExpression(String) Parse the expression} if it hasn't been already.
* <p>Parse the expression if it hasn't been already.
* @param cache the cache to use
* @param elementKey the element on which the expression is defined
* @param expression the expression to parse
@@ -86,21 +86,12 @@ public abstract class CachedExpressionEvaluator {
ExpressionKey expressionKey = createKey(elementKey, expression);
Expression expr = cache.get(expressionKey);
if (expr == null) {
expr = parseExpression(expression);
expr = getParser().parseExpression(expression);
cache.put(expressionKey, expr);
}
return expr;
}
/**
* Parse the specified {@code expression}.
* @param expression the expression to parse
* @since 5.3.13
*/
protected Expression parseExpression(String expression) {
return getParser().parseExpression(expression);
}
private ExpressionKey createKey(AnnotatedElementKey elementKey, String expression) {
return new ExpressionKey(elementKey, expression);
}
@@ -107,7 +107,7 @@ public final class CandidateComponentsIndexLoader {
result.add(properties);
}
if (logger.isDebugEnabled()) {
logger.debug("Loaded " + result.size() + " index(es)");
logger.debug("Loaded " + result.size() + "] index(es)");
}
int totalCount = result.stream().mapToInt(Properties::size).sum();
return (totalCount > 0 ? new CandidateComponentsIndex(result) : null);
@@ -1331,16 +1331,6 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
return getBeanFactory().findAnnotationOnBean(beanName, annotationType);
}
@Override
@Nullable
public <A extends Annotation> A findAnnotationOnBean(
String beanName, Class<A> annotationType, boolean allowFactoryBeanInit)
throws NoSuchBeanDefinitionException {
assertBeanFactoryActive();
return getBeanFactory().findAnnotationOnBean(beanName, annotationType, allowFactoryBeanInit);
}
//---------------------------------------------------------------------
// Implementation of HierarchicalBeanFactory interface
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,14 +16,11 @@
package org.springframework.scheduling.annotation;
import java.util.List;
import java.util.Collection;
import java.util.concurrent.Executor;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportAware;
@@ -31,7 +28,6 @@ import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.function.SingletonSupplier;
/**
* Abstract base {@code Configuration} class providing common structure for enabling
@@ -59,7 +55,7 @@ public abstract class AbstractAsyncConfiguration implements ImportAware {
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
this.enableAsync = AnnotationAttributes.fromMap(
importMetadata.getAnnotationAttributes(EnableAsync.class.getName()));
importMetadata.getAnnotationAttributes(EnableAsync.class.getName(), false));
if (this.enableAsync == null) {
throw new IllegalArgumentException(
"@EnableAsync is not present on importing class " + importMetadata.getClassName());
@@ -69,27 +65,17 @@ public abstract class AbstractAsyncConfiguration implements ImportAware {
/**
* Collect any {@link AsyncConfigurer} beans through autowiring.
*/
@Autowired
void setConfigurers(ObjectProvider<AsyncConfigurer> configurers) {
Supplier<AsyncConfigurer> configurer = SingletonSupplier.of(() -> {
List<AsyncConfigurer> candidates = configurers.stream().collect(Collectors.toList());
if (CollectionUtils.isEmpty(candidates)) {
return null;
}
if (candidates.size() > 1) {
throw new IllegalStateException("Only one AsyncConfigurer may exist");
}
return candidates.get(0);
});
this.executor = adapt(configurer, AsyncConfigurer::getAsyncExecutor);
this.exceptionHandler = adapt(configurer, AsyncConfigurer::getAsyncUncaughtExceptionHandler);
}
private <T> Supplier<T> adapt(Supplier<AsyncConfigurer> supplier, Function<AsyncConfigurer, T> provider) {
return () -> {
AsyncConfigurer configurer = supplier.get();
return (configurer != null ? provider.apply(configurer) : null);
};
@Autowired(required = false)
void setConfigurers(Collection<AsyncConfigurer> configurers) {
if (CollectionUtils.isEmpty(configurers)) {
return;
}
if (configurers.size() > 1) {
throw new IllegalStateException("Only one AsyncConfigurer may exist");
}
AsyncConfigurer configurer = configurers.iterator().next();
this.executor = configurer::getAsyncExecutor;
this.exceptionHandler = configurer::getAsyncUncaughtExceptionHandler;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,6 +28,11 @@ import org.springframework.lang.Nullable;
* {@link AsyncUncaughtExceptionHandler} instance used to process exception thrown from
* async method with {@code void} return type.
*
* <p>Consider using {@link AsyncConfigurerSupport} providing default implementations for
* both methods if only one element needs to be customized. Furthermore, backward compatibility
* of this interface will be insured in case new customization options are introduced
* in the future.
*
* <p>See @{@link EnableAsync} for usage examples.
*
* @author Chris Beams
@@ -35,6 +40,7 @@ import org.springframework.lang.Nullable;
* @since 3.1
* @see AbstractAsyncConfiguration
* @see EnableAsync
* @see AsyncConfigurerSupport
*/
public interface AsyncConfigurer {
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,7 +26,9 @@ import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
/**
@@ -63,7 +65,7 @@ import org.springframework.lang.Nullable;
*/
@SuppressWarnings("serial")
public class ThreadPoolExecutorFactoryBean extends ExecutorConfigurationSupport
implements FactoryBean<ExecutorService> {
implements FactoryBean<ExecutorService>, InitializingBean, DisposableBean {
private int corePoolSize = 1;
@@ -73,8 +75,6 @@ public class ThreadPoolExecutorFactoryBean extends ExecutorConfigurationSupport
private boolean allowCoreThreadTimeOut = false;
private boolean prestartAllCoreThreads = false;
private int queueCapacity = Integer.MAX_VALUE;
private boolean exposeUnconfigurableExecutor = false;
@@ -118,16 +118,6 @@ public class ThreadPoolExecutorFactoryBean extends ExecutorConfigurationSupport
this.allowCoreThreadTimeOut = allowCoreThreadTimeOut;
}
/**
* Specify whether to start all core threads, causing them to idly wait for work.
* <p>Default is "false".
* @since 5.3.14
* @see java.util.concurrent.ThreadPoolExecutor#prestartAllCoreThreads
*/
public void setPrestartAllCoreThreads(boolean prestartAllCoreThreads) {
this.prestartAllCoreThreads = prestartAllCoreThreads;
}
/**
* Set the capacity for the ThreadPoolExecutor's BlockingQueue.
* Default is {@code Integer.MAX_VALUE}.
@@ -163,9 +153,6 @@ public class ThreadPoolExecutorFactoryBean extends ExecutorConfigurationSupport
if (this.allowCoreThreadTimeOut) {
executor.allowCoreThreadTimeOut(true);
}
if (this.prestartAllCoreThreads) {
executor.prestartAllCoreThreads();
}
// Wrap executor with an unconfigurable decorator.
this.exposedExecutor = (this.exposeUnconfigurableExecutor ?
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -94,8 +94,6 @@ public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport
private boolean allowCoreThreadTimeOut = false;
private boolean prestartAllCoreThreads = false;
@Nullable
private TaskDecorator taskDecorator;
@@ -199,16 +197,6 @@ public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport
this.allowCoreThreadTimeOut = allowCoreThreadTimeOut;
}
/**
* Specify whether to start all core threads, causing them to idly wait for work.
* <p>Default is "false".
* @since 5.3.14
* @see java.util.concurrent.ThreadPoolExecutor#prestartAllCoreThreads
*/
public void setPrestartAllCoreThreads(boolean prestartAllCoreThreads) {
this.prestartAllCoreThreads = prestartAllCoreThreads;
}
/**
* Specify a custom {@link TaskDecorator} to be applied to any {@link Runnable}
* about to be executed.
@@ -268,9 +256,6 @@ public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport
if (this.allowCoreThreadTimeOut) {
executor.allowCoreThreadTimeOut(true);
}
if (this.prestartAllCoreThreads) {
executor.prestartAllCoreThreads();
}
this.threadPoolExecutor = executor;
return executor;
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -418,13 +418,11 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
}
/**
* Register fields that should be allowed for binding. Default is all fields.
* Restrict this for example to avoid unwanted modifications by malicious
* users when binding HTTP request parameters.
* <p>Supports "xxx*", "*xxx", "*xxx*" and "xxx*yyy" matches (with an
* arbitrary number of pattern parts), as well as direct equality. More
* sophisticated matching can be implemented by overriding the
* {@code isAllowed} method.
* Register fields that should be allowed for binding. Default is all
* fields. Restrict this for example to avoid unwanted modifications
* by malicious users when binding HTTP request parameters.
* <p>Supports "xxx*", "*xxx" and "*xxx*" patterns. More sophisticated matching
* can be implemented by overriding the {@code isAllowed} method.
* <p>Alternatively, specify a list of <i>disallowed</i> fields.
* @param allowedFields array of field names
* @see #setDisallowedFields
@@ -444,13 +442,11 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
}
/**
* Register fields that should <i>not</i> be allowed for binding. Default
* is none. Mark fields as disallowed for example to avoid unwanted
* modifications by malicious users when binding HTTP request parameters.
* <p>Supports "xxx*", "*xxx", "*xxx*" and "xxx*yyy" matches (with an
* arbitrary number of pattern parts), as well as direct equality.
* More sophisticated matching can be implemented by overriding the
* {@code isAllowed} method.
* Register fields that should <i>not</i> be allowed for binding. Default is none.
* Mark fields as disallowed for example to avoid unwanted modifications
* by malicious users when binding HTTP request parameters.
* <p>Supports "xxx*", "*xxx" and "*xxx*" patterns. More sophisticated matching
* can be implemented by overriding the {@code isAllowed} method.
* <p>Alternatively, specify a list of <i>allowed</i> fields.
* @param disallowedFields array of field names
* @see #setAllowedFields
@@ -776,11 +772,10 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
/**
* Return if the given field is allowed for binding.
* Invoked for each passed-in property value.
* <p>The default implementation checks for "xxx*", "*xxx", "*xxx*" and "xxx*yyy"
* matches (with an arbitrary number of pattern parts), as well as direct equality,
* in the specified lists of allowed fields and disallowed fields. A field matching
* a disallowed pattern will not be accepted even if it also happens to match a
* pattern in the allowed list.
* <p>The default implementation checks for "xxx*", "*xxx" and "*xxx*" matches,
* as well as direct equality, in the specified lists of allowed fields and
* disallowed fields. A field matching a disallowed pattern will not be accepted
* even if it also happens to match a pattern in the allowed list.
* <p>Can be overridden in subclasses.
* @param field the field to check
* @return if the field is allowed
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -65,10 +65,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIOException;
/**
* @since 13.03.2003
* @author Rod Johnson
* @author Juergen Hoeller
* @author Chris Beams
* @since 13.03.2003
*/
public class ProxyFactoryBeanTests {
@@ -633,50 +633,20 @@ public class ProxyFactoryBeanTests {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(FROZEN_CONTEXT, CLASS));
Advised advised = (Advised) bf.getBean("frozen");
Advised advised = (Advised)bf.getBean("frozen");
assertThat(advised.isFrozen()).as("The proxy should be frozen").isTrue();
}
@Test
public void testDetectsInterfaces() {
public void testDetectsInterfaces() throws Exception {
ProxyFactoryBean fb = new ProxyFactoryBean();
fb.setTarget(new TestBean());
fb.addAdvice(new DebugInterceptor());
fb.setBeanFactory(new DefaultListableBeanFactory());
ITestBean proxy = (ITestBean) fb.getObject();
assertThat(AopUtils.isJdkDynamicProxy(proxy)).isTrue();
}
@Test
public void testWithInterceptorNames() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerSingleton("debug", new DebugInterceptor());
ProxyFactoryBean fb = new ProxyFactoryBean();
fb.setTarget(new TestBean());
fb.setInterceptorNames("debug");
fb.setBeanFactory(bf);
Advised proxy = (Advised) fb.getObject();
assertThat(proxy.getAdvisorCount()).isEqualTo(1);
}
@Test
public void testWithLateInterceptorNames() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerSingleton("debug", new DebugInterceptor());
ProxyFactoryBean fb = new ProxyFactoryBean();
fb.setTarget(new TestBean());
fb.setBeanFactory(bf);
fb.getObject();
fb.setInterceptorNames("debug");
Advised proxy = (Advised) fb.getObject();
assertThat(proxy.getAdvisorCount()).isEqualTo(1);
}
/**
* Fires only on void methods. Saves list of methods intercepted.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -196,7 +196,7 @@ class CommonsPool2TargetSourceTests {
void testSetWhenExhaustedAction() {
CommonsPool2TargetSource targetSource = new CommonsPool2TargetSource();
targetSource.setBlockWhenExhausted(true);
assertThat(targetSource.isBlockWhenExhausted()).isTrue();
assertThat(targetSource.isBlockWhenExhausted()).isEqualTo(true);
}
@Test
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -876,7 +876,7 @@ class XmlBeanFactoryTests {
// should have been autowired
assertThat(rod1.getSpouse1()).isEqualTo(kerry);
assertThat(rod1.getAge()).isEqualTo(0);
assertThat(rod1.getName()).isNull();
assertThat(rod1.getName()).isEqualTo(null);
ConstructorDependenciesBean rod2 = (ConstructorDependenciesBean) xbf.getBean("rod2");
TestBean kerry1 = (TestBean) xbf.getBean("kerry1");
@@ -885,7 +885,7 @@ class XmlBeanFactoryTests {
assertThat(rod2.getSpouse1()).isEqualTo(kerry2);
assertThat(rod2.getSpouse2()).isEqualTo(kerry1);
assertThat(rod2.getAge()).isEqualTo(0);
assertThat(rod2.getName()).isNull();
assertThat(rod2.getName()).isEqualTo(null);
ConstructorDependenciesBean rod = (ConstructorDependenciesBean) xbf.getBean("rod3");
IndexedTestBean other = (IndexedTestBean) xbf.getBean("other");
@@ -894,7 +894,7 @@ class XmlBeanFactoryTests {
assertThat(rod.getSpouse2()).isEqualTo(kerry);
assertThat(rod.getOther()).isEqualTo(other);
assertThat(rod.getAge()).isEqualTo(0);
assertThat(rod.getName()).isNull();
assertThat(rod.getName()).isEqualTo(null);
xbf.getBean("rod4", ConstructorDependenciesBean.class);
// should have been autowired
@@ -902,7 +902,7 @@ class XmlBeanFactoryTests {
assertThat(rod.getSpouse2()).isEqualTo(kerry);
assertThat(rod.getOther()).isEqualTo(other);
assertThat(rod.getAge()).isEqualTo(0);
assertThat(rod.getName()).isNull();
assertThat(rod.getName()).isEqualTo(null);
}
@Test
@@ -929,7 +929,7 @@ class XmlBeanFactoryTests {
assertThat(rod6.getSpouse2()).isEqualTo(kerry1);
assertThat(rod6.getOther()).isEqualTo(other);
assertThat(rod6.getAge()).isEqualTo(0);
assertThat(rod6.getName()).isNull();
assertThat(rod6.getName()).isEqualTo(null);
xbf.destroySingletons();
assertThat(rod6.destroyed).isTrue();
@@ -967,7 +967,7 @@ class XmlBeanFactoryTests {
assertThat(rod9c.getAge()).isEqualTo(97);
ConstructorDependenciesBean rod10 = (ConstructorDependenciesBean) xbf.getBean("rod10");
assertThat(rod10.getName()).isNull();
assertThat(rod10.getName()).isEqualTo(null);
ConstructorDependenciesBean rod11 = (ConstructorDependenciesBean) xbf.getBean("rod11");
assertThat(rod11.getSpouse1()).isEqualTo(kerry2);
@@ -1331,7 +1331,7 @@ class XmlBeanFactoryTests {
OverrideOneMethodSubclass ooms = (OverrideOneMethodSubclass) xbf.getBean("replaceVoidMethod");
DoSomethingReplacer dos = (DoSomethingReplacer) xbf.getBean("doSomethingReplacer");
assertThat(dos.lastArg).isNull();
assertThat(dos.lastArg).isEqualTo(null);
String s1 = "";
String s2 = "foo bar black sheep";
ooms.doSomething(s1);
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@ import org.springframework.beans.testfixture.beans.TestBean;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.cache.annotation.CachingConfigurer;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCache;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
@@ -306,7 +306,7 @@ public class CacheReproTests {
@Configuration
@EnableCaching
public static class Spr13081Config implements CachingConfigurer {
public static class Spr13081Config extends CachingConfigurerSupport {
@Bean
@Override
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@ import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.CachingConfigurer;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -83,19 +83,6 @@ public class EnableCachingIntegrationTests {
assertCacheHit(key, value, cache);
}
@Test
public void barServiceWithCacheableInterfaceCglib() {
this.context = new AnnotationConfigApplicationContext(BarConfigCglib.class);
BarService service = this.context.getBean(BarService.class);
Cache cache = getCache();
Object key = new Object();
assertCacheMiss(key, cache);
Object value = service.getSimple(key);
assertCacheHit(key, value, cache);
}
@Test
public void beanConditionOff() {
this.context = new AnnotationConfigApplicationContext(BeanConditionConfig.class);
@@ -137,7 +124,7 @@ public class EnableCachingIntegrationTests {
@Configuration
static class SharedConfig implements CachingConfigurer {
static class SharedConfig extends CachingConfigurerSupport {
@Override
@Bean
@@ -198,36 +185,6 @@ public class EnableCachingIntegrationTests {
}
@Configuration
@Import(SharedConfig.class)
@EnableCaching(proxyTargetClass = true)
static class BarConfigCglib {
@Bean
public BarService barService() {
return new BarServiceImpl();
}
}
interface BarService {
@Cacheable(cacheNames = "testCache")
Object getSimple(Object key);
}
static class BarServiceImpl implements BarService {
private final AtomicLong counter = new AtomicLong();
@Override
public Object getSimple(Object key) {
return this.counter.getAndIncrement();
}
}
@Configuration
@Import(FooConfig.class)
@EnableCaching
@@ -18,10 +18,11 @@ package org.springframework.cache.config;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurer;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.CacheErrorHandler;
import org.springframework.cache.interceptor.CacheInterceptor;
@@ -106,8 +107,11 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
try {
ctx.refresh();
}
catch (IllegalStateException ex) {
assertThat(ex.getMessage().contains("implementations of CachingConfigurer")).isTrue();
catch (BeanCreationException ex) {
Throwable root = ex.getRootCause();
boolean condition = root instanceof IllegalStateException;
assertThat(condition).isTrue();
assertThat(root.getMessage().contains("implementations of CachingConfigurer")).isTrue();
}
}
@@ -146,7 +150,7 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
@Configuration
@EnableCaching
static class EnableCachingConfig implements CachingConfigurer {
static class EnableCachingConfig extends CachingConfigurerSupport {
@Override
@Bean
@@ -223,7 +227,7 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
@Configuration
@EnableCaching
static class MultiCacheManagerConfigurer implements CachingConfigurer {
static class MultiCacheManagerConfigurer extends CachingConfigurerSupport {
@Bean
public CacheManager cm1() {
@@ -249,7 +253,7 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
@Configuration
@EnableCaching
static class EmptyConfigSupportConfig implements CachingConfigurer {
static class EmptyConfigSupportConfig extends CachingConfigurerSupport {
@Bean
public CacheManager cm() {
@@ -260,7 +264,7 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
@Configuration
@EnableCaching
static class FullCachingConfig implements CachingConfigurer {
static class FullCachingConfig extends CachingConfigurerSupport {
@Override
@Bean
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.CachingConfigurer;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.context.ConfigurableApplicationContext;
@@ -122,7 +122,7 @@ public class ExpressionCachingIntegrationTests {
@Configuration
@EnableCaching
static class SharedConfig implements CachingConfigurer {
static class SharedConfig extends CachingConfigurerSupport {
@Override
@Bean
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@ import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.CachingConfigurer;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.cache.support.SimpleValueWrapper;
@@ -170,7 +170,7 @@ public class CacheErrorHandlerTests {
@Configuration
@EnableCaching
static class Config implements CachingConfigurer {
static class Config extends CachingConfigurerSupport {
@Bean
@Override
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@ import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.CachingConfigurer;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.context.ConfigurableApplicationContext;
@@ -106,7 +106,7 @@ public class CachePutEvaluationTests {
@Configuration
@EnableCaching
static class Config implements CachingConfigurer {
static class Config extends CachingConfigurerSupport {
@Bean
@Override
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,7 +29,7 @@ import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.CachingConfigurer;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -149,7 +149,7 @@ public class CacheResolverCustomizationTests {
@Configuration
@EnableCaching
static class Config implements CachingConfigurer {
static class Config extends CachingConfigurerSupport {
@Override
@Bean
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@ import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.cache.annotation.CachingConfigurer;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -133,7 +133,7 @@ public class CacheSyncFailureTests {
@Configuration
@EnableCaching
static class Config implements CachingConfigurer {
static class Config extends CachingConfigurerSupport {
@Override
@Bean
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,7 +47,7 @@ public class PrimitiveBeanLookupAndAutowiringTests {
public void primitiveLookupByName() {
ApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
boolean b = ctx.getBean("b", boolean.class);
assertThat(b).isTrue();
assertThat(b).isEqualTo(true);
int i = ctx.getBean("i", int.class);
assertThat(i).isEqualTo(42);
}
@@ -56,7 +56,7 @@ public class PrimitiveBeanLookupAndAutowiringTests {
public void primitiveLookupByType() {
ApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
boolean b = ctx.getBean(boolean.class);
assertThat(b).isTrue();
assertThat(b).isEqualTo(true);
int i = ctx.getBean(int.class);
assertThat(i).isEqualTo(42);
}
@@ -65,7 +65,7 @@ public class PrimitiveBeanLookupAndAutowiringTests {
public void primitiveAutowiredInjection() {
ApplicationContext ctx =
new AnnotationConfigApplicationContext(Config.class, AutowiredComponent.class);
assertThat(ctx.getBean(AutowiredComponent.class).b).isTrue();
assertThat(ctx.getBean(AutowiredComponent.class).b).isEqualTo(true);
assertThat(ctx.getBean(AutowiredComponent.class).i).isEqualTo(42);
}
@@ -73,7 +73,7 @@ public class PrimitiveBeanLookupAndAutowiringTests {
public void primitiveResourceInjection() {
ApplicationContext ctx =
new AnnotationConfigApplicationContext(Config.class, ResourceComponent.class);
assertThat(ctx.getBean(ResourceComponent.class).b).isTrue();
assertThat(ctx.getBean(ResourceComponent.class).b).isEqualTo(true);
assertThat(ctx.getBean(ResourceComponent.class).i).isEqualTo(42);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,7 +27,6 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.InstanceOfAssertFactories.BOOLEAN;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -44,7 +43,7 @@ public class CachedExpressionEvaluatorTests {
Method method = ReflectionUtils.findMethod(getClass(), "toString");
Expression expression = expressionEvaluator.getTestExpression("true", method, getClass());
hasParsedExpression("true");
assertThat(expression.getValue()).asInstanceOf(BOOLEAN).isTrue();
assertThat(expression.getValue()).isEqualTo(true);
assertThat(expressionEvaluator.testCache.size()).as("Expression should be in cache").isEqualTo(1);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -67,17 +67,6 @@ public class MapAccessorTests {
assertThat(ex.getValue(sec,mapGetter)).isEqualTo("bar");
assertThat(SpelCompiler.compile(ex)).isTrue();
assertThat(ex.getValue(sec,mapGetter)).isEqualTo("bar");
// basic isWritable
ex = sep.parseExpression("foo");
assertThat(ex.isWritable(sec,testMap)).isTrue();
// basic write
ex = sep.parseExpression("foo2");
ex.setValue(sec, testMap, "bar2");
assertThat(ex.getValue(sec,testMap)).isEqualTo("bar2");
assertThat(SpelCompiler.compile(ex)).isTrue();
assertThat(ex.getValue(sec,testMap)).isEqualTo("bar2");
}
public static class MapGetter {
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +25,6 @@ import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.InstanceOfAssertFactories.BOOLEAN;
/**
* Unit tests for {@link MethodBasedEvaluationContext}.
@@ -48,9 +47,9 @@ public class MethodBasedEvaluationContextTests {
assertThat(context.lookupVariable("p0")).isEqualTo("test");
assertThat(context.lookupVariable("foo")).isEqualTo("test");
assertThat(context.lookupVariable("a1")).asInstanceOf(BOOLEAN).isTrue();
assertThat(context.lookupVariable("p1")).asInstanceOf(BOOLEAN).isTrue();
assertThat(context.lookupVariable("flag")).asInstanceOf(BOOLEAN).isTrue();
assertThat(context.lookupVariable("a1")).isEqualTo(true);
assertThat(context.lookupVariable("p1")).isEqualTo(true);
assertThat(context.lookupVariable("flag")).isEqualTo(true);
assertThat(context.lookupVariable("a2")).isNull();
assertThat(context.lookupVariable("p2")).isNull();
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -345,7 +345,7 @@ public class PropertySourcesPlaceholderConfigurerTests {
.addPropertyValue("jedi", "${jedi:false}")
.getBeanDefinition());
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).isJedi()).isTrue();
assertThat(bf.getBean(TestBean.class).isJedi()).isEqualTo(true);
}
@Test
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -281,7 +281,7 @@ public class FormattingConversionServiceTests {
@Test
public void printNullDefault() {
assertThat(formattingService
.convert(null, TypeDescriptor.valueOf(Integer.class), TypeDescriptor.valueOf(String.class))).isNull();
.convert(null, TypeDescriptor.valueOf(Integer.class), TypeDescriptor.valueOf(String.class))).isEqualTo(null);
}
@Test
@@ -321,6 +321,28 @@ public class FormattingConversionServiceTests {
TypeDescriptor.valueOf(String.class));
}
@Test
public void registerDefaultValueViaFormatter() {
registerDefaultValue(Date.class, new Date());
}
private <T> void registerDefaultValue(Class<T> clazz, final T defaultValue) {
formattingService.addFormatterForFieldType(clazz, new Formatter<T>() {
@Override
public T parse(String text, Locale locale) {
return defaultValue;
}
@Override
public String print(T t, Locale locale) {
return defaultValue.toString();
}
@Override
public String toString() {
return defaultValue.toString();
}
});
}
@Test
public void introspectedFormatter() {
formattingService.addFormatter(new NumberStyleFormatter("#,#00.0#"));
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,7 +42,7 @@ public class JndiLocatorDelegateTests {
builderField.set(null, null);
try {
assertThat(JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()).isFalse();
assertThat(JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()).isEqualTo(false);
}
finally {
builderField.set(null, oldBuilder);
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -218,8 +218,8 @@ public class AsyncAnnotationBeanPostProcessorTests {
private void assertFutureWithException(Future<Object> result,
TestableAsyncUncaughtExceptionHandler exceptionHandler) {
assertThatExceptionOfType(ExecutionException.class).isThrownBy(
result::get)
.withCauseExactlyInstanceOf(UnsupportedOperationException.class);
result::get)
.withCauseExactlyInstanceOf(UnsupportedOperationException.class);
assertThat(exceptionHandler.isCalled()).as("handler should never be called with Future return type").isFalse();
}
@@ -343,7 +343,7 @@ public class AsyncAnnotationBeanPostProcessorTests {
@Configuration
@EnableAsync
static class ConfigWithExceptionHandler implements AsyncConfigurer {
static class ConfigWithExceptionHandler extends AsyncConfigurerSupport {
@Bean
public ITestBean target() {
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,12 +16,8 @@
package org.springframework.scheduling.concurrent;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.FutureTask;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import org.junit.jupiter.api.Test;
@@ -29,16 +25,10 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.GenericApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link ThreadPoolExecutorFactoryBean}.
*
* @author Juergen Hoeller
*/
class ThreadPoolExecutorFactoryBeanTests {
@@ -54,28 +44,6 @@ class ThreadPoolExecutorFactoryBeanTests {
context.close();
}
@Test
void executorWithDefaultSettingsDoesNotPrestartAllCoreThreads() {
GenericApplicationContext context = new GenericApplicationContext();
context.registerBean("taskExecutor", ThreadPoolExecutorFactoryBean.class, TestThreadPoolExecutorFactoryBean::new);
context.refresh();
ThreadPoolExecutor threadPoolExecutor = context.getBean(ThreadPoolExecutor.class);
verify(threadPoolExecutor, never()).prestartAllCoreThreads();
}
@Test
void executorWithPrestartAllCoreThreads() {
GenericApplicationContext context = new GenericApplicationContext();
context.registerBean("taskExecutor", ThreadPoolExecutorFactoryBean.class, () -> {
TestThreadPoolExecutorFactoryBean factoryBean = new TestThreadPoolExecutorFactoryBean();
factoryBean.setPrestartAllCoreThreads(true);
return factoryBean;
});
context.refresh();
ThreadPoolExecutor threadPoolExecutor = context.getBean(ThreadPoolExecutor.class);
verify(threadPoolExecutor).prestartAllCoreThreads();
}
@Configuration
static class ExecutorConfig {
@@ -84,19 +52,7 @@ class ThreadPoolExecutorFactoryBeanTests {
ThreadPoolExecutorFactoryBean executor() {
return new ThreadPoolExecutorFactoryBean();
}
}
@SuppressWarnings("serial")
private static class TestThreadPoolExecutorFactoryBean extends ThreadPoolExecutorFactoryBean {
@Override
protected ThreadPoolExecutor createExecutor(
int corePoolSize, int maxPoolSize, int keepAliveSeconds, BlockingQueue<Runnable> queue,
ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
return mock(ThreadPoolExecutor.class);
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,7 +57,7 @@ public class ExecutorBeanDefinitionParserTests {
assertThat(getMaxPoolSize(executor)).isEqualTo(Integer.MAX_VALUE);
assertThat(getQueueCapacity(executor)).isEqualTo(Integer.MAX_VALUE);
assertThat(getKeepAliveSeconds(executor)).isEqualTo(60);
assertThat(getAllowCoreThreadTimeOut(executor)).isFalse();
assertThat(getAllowCoreThreadTimeOut(executor)).isEqualTo(false);
FutureTask<String> task = new FutureTask<>(new Callable<String>() {
@Override
@@ -96,7 +96,7 @@ public class ExecutorBeanDefinitionParserTests {
assertThat(getCorePoolSize(executor)).isEqualTo(9);
assertThat(getMaxPoolSize(executor)).isEqualTo(9);
assertThat(getKeepAliveSeconds(executor)).isEqualTo(37);
assertThat(getAllowCoreThreadTimeOut(executor)).isTrue();
assertThat(getAllowCoreThreadTimeOut(executor)).isEqualTo(true);
assertThat(getQueueCapacity(executor)).isEqualTo(Integer.MAX_VALUE);
}
@@ -106,7 +106,7 @@ public class ExecutorBeanDefinitionParserTests {
assertThat(getCorePoolSize(executor)).isEqualTo(123);
assertThat(getMaxPoolSize(executor)).isEqualTo(123);
assertThat(getKeepAliveSeconds(executor)).isEqualTo(60);
assertThat(getAllowCoreThreadTimeOut(executor)).isFalse();
assertThat(getAllowCoreThreadTimeOut(executor)).isEqualTo(false);
assertThat(getQueueCapacity(executor)).isEqualTo(Integer.MAX_VALUE);
}
@@ -115,7 +115,7 @@ public class ExecutorBeanDefinitionParserTests {
Object executor = this.context.getBean("propertyPlaceholderWithRange");
assertThat(getCorePoolSize(executor)).isEqualTo(5);
assertThat(getMaxPoolSize(executor)).isEqualTo(25);
assertThat(getAllowCoreThreadTimeOut(executor)).isFalse();
assertThat(getAllowCoreThreadTimeOut(executor)).isEqualTo(false);
assertThat(getQueueCapacity(executor)).isEqualTo(10);
}
@@ -124,7 +124,7 @@ public class ExecutorBeanDefinitionParserTests {
Object executor = this.context.getBean("propertyPlaceholderWithRangeAndCoreThreadTimeout");
assertThat(getCorePoolSize(executor)).isEqualTo(99);
assertThat(getMaxPoolSize(executor)).isEqualTo(99);
assertThat(getAllowCoreThreadTimeOut(executor)).isTrue();
assertThat(getAllowCoreThreadTimeOut(executor)).isEqualTo(true);
}
@Test
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1242,7 +1242,7 @@ class DataBinderTests {
assertThat(errors.getFieldError("name").getCodes()[2]).isEqualTo("NOT_ROD.java.lang.String");
assertThat(errors.getFieldError("name").getCodes()[3]).isEqualTo("NOT_ROD");
assertThat((errors.getFieldErrors("name").get(0)).getField()).isEqualTo("name");
assertThat((errors.getFieldErrors("name").get(0)).getRejectedValue()).isNull();
assertThat((errors.getFieldErrors("name").get(0)).getRejectedValue()).isEqualTo(null);
assertThat(errors.hasFieldErrors("spouse.age")).isTrue();
assertThat(errors.getFieldErrorCount("spouse.age")).isEqualTo(1);
@@ -1314,7 +1314,7 @@ class DataBinderTests {
assertThat(errors.getFieldError("name").getCodes()[2]).isEqualTo("validation.NOT_ROD.java.lang.String");
assertThat(errors.getFieldError("name").getCodes()[3]).isEqualTo("validation.NOT_ROD");
assertThat((errors.getFieldErrors("name").get(0)).getField()).isEqualTo("name");
assertThat((errors.getFieldErrors("name").get(0)).getRejectedValue()).isNull();
assertThat((errors.getFieldErrors("name").get(0)).getRejectedValue()).isEqualTo(null);
assertThat(errors.hasFieldErrors("spouse.age")).isTrue();
assertThat(errors.getFieldErrorCount("spouse.age")).isEqualTo(1);
@@ -1339,7 +1339,7 @@ class DataBinderTests {
assertThat(errors.getFieldErrorCount("spouse")).isEqualTo(1);
assertThat(errors.getFieldError("spouse").getCode()).isEqualTo("SPOUSE_NOT_AVAILABLE");
assertThat((errors.getFieldErrors("spouse").get(0)).getObjectName()).isEqualTo("tb");
assertThat((errors.getFieldErrors("spouse").get(0)).getRejectedValue()).isNull();
assertThat((errors.getFieldErrors("spouse").get(0)).getRejectedValue()).isEqualTo(null);
}
@Test
@@ -194,7 +194,7 @@ public class ClassReader {
this.b = classFileBuffer;
// Check the class' major_version. This field is after the magic and minor_version fields, which
// use 4 and 2 bytes respectively.
if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V19) {
if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V18) {
throw new IllegalArgumentException(
"Unsupported class file major version " + readShort(classFileOffset + 6));
}
@@ -283,7 +283,6 @@ public interface Opcodes {
int V16 = 0 << 16 | 60;
int V17 = 0 << 16 | 61;
int V18 = 0 << 16 | 62;
int V19 = 0 << 16 | 63;
/**
* Version flag indicating that the class is using 'preview' features.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -101,8 +101,6 @@ public class LocalVariableTableParameterNameDiscoverer implements ParameterNameD
}
return NO_DEBUG_INFO_MAP;
}
// We cannot use try-with-resources here for the InputStream, since we have
// custom handling of the close() method in a finally-block.
try {
ClassReader classReader = new ClassReader(is);
Map<Executable, String[]> map = new ConcurrentHashMap<>(32);
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,11 +48,11 @@ import org.springframework.util.StringUtils;
* {@link #getGeneric(int...) generic parameters} along with the ability to ultimately
* {@link #resolve() resolve} to a {@link java.lang.Class}.
*
* <p>A {@code ResolvableType} may be obtained from a {@linkplain #forField(Field) field},
* a {@linkplain #forMethodParameter(Method, int) method parameter},
* a {@linkplain #forMethodReturnType(Method) method return type}, or a
* {@linkplain #forClass(Class) class}. Most methods on this class will themselves return
* a {@code ResolvableType}, allowing for easy navigation. For example:
* <p>{@code ResolvableTypes} may be obtained from {@link #forField(Field) fields},
* {@link #forMethodParameter(Method, int) method parameters},
* {@link #forMethodReturnType(Method) method returns} or
* {@link #forClass(Class) classes}. Most methods on this class will themselves return
* {@link ResolvableType ResolvableTypes}, allowing easy navigation. For example:
* <pre class="code">
* private HashMap&lt;Integer, List&lt;String&gt;&gt; myMap;
*
@@ -182,7 +182,7 @@ public class ResolvableType implements Serializable {
/**
* Private constructor used to create a new {@link ResolvableType} on a {@link Class} basis.
* <p>Avoids all {@code instanceof} checks in order to create a straight {@link Class} wrapper.
* Avoids all {@code instanceof} checks in order to create a straight {@link Class} wrapper.
* @since 4.2
*/
private ResolvableType(@Nullable Class<?> clazz) {
@@ -406,7 +406,7 @@ public class ResolvableType implements Serializable {
/**
* Convenience method to return this type as a resolvable {@link Collection} type.
* <p>Returns {@link #NONE} if this type does not implement or extend
* Returns {@link #NONE} if this type does not implement or extend
* {@link Collection}.
* @see #as(Class)
* @see #asMap()
@@ -417,7 +417,7 @@ public class ResolvableType implements Serializable {
/**
* Convenience method to return this type as a resolvable {@link Map} type.
* <p>Returns {@link #NONE} if this type does not implement or extend
* Returns {@link #NONE} if this type does not implement or extend
* {@link Map}.
* @see #as(Class)
* @see #asCollection()
@@ -458,7 +458,7 @@ public class ResolvableType implements Serializable {
/**
* Return a {@link ResolvableType} representing the direct supertype of this type.
* <p>If no supertype is available this method returns {@link #NONE}.
* If no supertype is available this method returns {@link #NONE}.
* <p>Note: The resulting {@link ResolvableType} instance may not be {@link Serializable}.
* @see #getInterfaces()
*/
@@ -608,7 +608,7 @@ public class ResolvableType implements Serializable {
/**
* Return a {@link ResolvableType} for the specified nesting level.
* <p>See {@link #getNested(int, Map)} for details.
* See {@link #getNested(int, Map)} for details.
* @param nestingLevel the nesting level
* @return the {@link ResolvableType} type, or {@code #NONE}
*/
@@ -999,7 +999,7 @@ public class ResolvableType implements Serializable {
/**
* Return a {@link ResolvableType} for the specified {@link Class},
* using the full generic type information for assignability checks.
* <p>For example: {@code ResolvableType.forClass(MyArrayList.class)}.
* For example: {@code ResolvableType.forClass(MyArrayList.class)}.
* @param clazz the class to introspect ({@code null} is semantically
* equivalent to {@code Object.class} for typical use cases here)
* @return a {@link ResolvableType} for the specified class
@@ -1014,7 +1014,7 @@ public class ResolvableType implements Serializable {
* Return a {@link ResolvableType} for the specified {@link Class},
* doing assignability checks against the raw class only (analogous to
* {@link Class#isAssignableFrom}, which this serves as a wrapper for.
* <p>For example: {@code ResolvableType.forRawClass(List.class)}.
* For example: {@code ResolvableType.forRawClass(List.class)}.
* @param clazz the class to introspect ({@code null} is semantically
* equivalent to {@code Object.class} for typical use cases here)
* @return a {@link ResolvableType} for the specified class
@@ -1043,7 +1043,7 @@ public class ResolvableType implements Serializable {
/**
* Return a {@link ResolvableType} for the specified base type
* (interface or base class) with a given implementation class.
* <p>For example: {@code ResolvableType.forClass(List.class, MyArrayList.class)}.
* For example: {@code ResolvableType.forClass(List.class, MyArrayList.class)}.
* @param baseType the base type (must not be {@code null})
* @param implementationClass the implementation class
* @return a {@link ResolvableType} for the specified base type backed by the
@@ -1085,7 +1085,7 @@ public class ResolvableType implements Serializable {
Assert.notNull(clazz, "Class must not be null");
Assert.notNull(generics, "Generics array must not be null");
TypeVariable<?>[] variables = clazz.getTypeParameters();
Assert.isTrue(variables.length == generics.length, () -> "Mismatched number of generics specified for " + clazz.toGenericString());
Assert.isTrue(variables.length == generics.length, "Mismatched number of generics specified");
Type[] arguments = new Type[generics.length];
for (int i = 0; i < generics.length; i++) {
@@ -1238,7 +1238,7 @@ public class ResolvableType implements Serializable {
/**
* Return a {@link ResolvableType} for the specified {@link Method} return type.
* <p>Use this variant when the class that declares the method includes generic
* Use this variant when the class that declares the method includes generic
* parameter variables that are satisfied by the implementation class.
* @param method the source for the method return type
* @param implementationClass the implementation class
@@ -37,7 +37,7 @@ import org.springframework.util.ObjectUtils;
/**
* Contextual descriptor about a type to convert from or to.
* <p>Capable of representing arrays and generic collection types.
* Capable of representing arrays and generic collection types.
*
* @author Keith Donald
* @author Andy Clement
@@ -345,9 +345,9 @@ public class TypeDescriptor implements Serializable {
* from the provided collection or array element.
* <p>Narrows the {@link #getElementTypeDescriptor() elementType} property to the class
* of the provided collection or array element. For example, if this describes a
* {@code java.util.List<java.lang.Number>} and the element argument is a
* {@code java.util.List&lt;java.lang.Number&lt;} and the element argument is an
* {@code java.lang.Integer}, the returned TypeDescriptor will be {@code java.lang.Integer}.
* If this describes a {@code java.util.List<?>} and the element argument is a
* If this describes a {@code java.util.List&lt;?&gt;} and the element argument is an
* {@code java.lang.Integer}, the returned TypeDescriptor will be {@code java.lang.Integer}
* as well.
* <p>Annotation and nested type context will be preserved in the narrowed
@@ -388,9 +388,9 @@ public class TypeDescriptor implements Serializable {
* from the provided map key.
* <p>Narrows the {@link #getMapKeyTypeDescriptor() mapKeyType} property
* to the class of the provided map key. For example, if this describes a
* {@code java.util.Map<java.lang.Number, java.lang.String>} and the key
* {@code java.util.Map&lt;java.lang.Number, java.lang.String&lt;} and the key
* argument is a {@code java.lang.Integer}, the returned TypeDescriptor will be
* {@code java.lang.Integer}. If this describes a {@code java.util.Map<?, ?>}
* {@code java.lang.Integer}. If this describes a {@code java.util.Map&lt;?, ?&gt;}
* and the key argument is a {@code java.lang.Integer}, the returned
* TypeDescriptor will be {@code java.lang.Integer} as well.
* <p>Annotation and nested type context will be preserved in the narrowed
@@ -425,9 +425,9 @@ public class TypeDescriptor implements Serializable {
* from the provided map value.
* <p>Narrows the {@link #getMapValueTypeDescriptor() mapValueType} property
* to the class of the provided map value. For example, if this describes a
* {@code java.util.Map<java.lang.String, java.lang.Number>} and the value
* {@code java.util.Map&lt;java.lang.String, java.lang.Number&lt;} and the value
* argument is a {@code java.lang.Integer}, the returned TypeDescriptor will be
* {@code java.lang.Integer}. If this describes a {@code java.util.Map<?, ?>}
* {@code java.lang.Integer}. If this describes a {@code java.util.Map&lt;?, ?&gt;}
* and the value argument is a {@code java.lang.Integer}, the returned
* TypeDescriptor will be {@code java.lang.Integer} as well.
* <p>Annotation and nested type context will be preserved in the narrowed
@@ -17,12 +17,10 @@
package org.springframework.core.log;
import java.util.function.Function;
import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
/**
* Utility methods for formatting and logging messages.
@@ -37,15 +35,9 @@ import org.springframework.util.ObjectUtils;
*/
public abstract class LogFormatUtils {
private static final Pattern NEWLINE_PATTERN = Pattern.compile("[\n\r]");
private static final Pattern CONTROL_CHARACTER_PATTERN = Pattern.compile("\\p{Cc}");
/**
* Convenience variant of {@link #formatValue(Object, int, boolean)} that
* limits the length of a log message to 100 characters and also replaces
* newline and control characters if {@code limitLength} is set to "true".
* Variant of {@link #formatValue(Object, int, boolean)} and a convenience
* method that truncates at 100 characters when {@code limitLength} is set.
* @param value the value to format
* @param limitLength whether to truncate the value at a length of 100
* @return the formatted value
@@ -60,29 +52,25 @@ public abstract class LogFormatUtils {
* compacting it into a single line when {@code replaceNewLines} is set.
* @param value the value to be formatted
* @param maxLength the max length, after which to truncate, or -1 for unlimited
* @param replaceNewlinesAndControlCharacters whether to replace newline and
* control characters with placeholders
* @param replaceNewlines whether to replace newline characters with placeholders
* @return the formatted value
*/
public static String formatValue(
@Nullable Object value, int maxLength, boolean replaceNewlinesAndControlCharacters) {
public static String formatValue(@Nullable Object value, int maxLength, boolean replaceNewlines) {
if (value == null) {
return "";
}
String result;
try {
result = ObjectUtils.nullSafeToString(value);
result = value.toString();
}
catch (Throwable ex) {
result = ObjectUtils.nullSafeToString(ex);
result = ex.toString();
}
if (maxLength != -1) {
result = (result.length() > maxLength ? result.substring(0, maxLength) + " (truncated)..." : result);
}
if (replaceNewlinesAndControlCharacters) {
result = NEWLINE_PATTERN.matcher(result).replaceAll("<EOL>");
result = CONTROL_CHARACTER_PATTERN.matcher(result).replaceAll("?");
if (replaceNewlines) {
result = result.replace("\n", "<LF>").replace("\r", "<CR>");
}
if (value instanceof CharSequence) {
result = "\"" + result + "\"";
@@ -162,7 +162,7 @@ public class StandardAnnotationMetadata extends StandardClassMetadata implements
throw new IllegalStateException("Failed to introspect annotated methods on " + getIntrospectedClass(), ex);
}
}
return (annotatedMethods != null ? annotatedMethods : Collections.emptySet());
return annotatedMethods != null ? annotatedMethods : Collections.emptySet();
}
@@ -127,11 +127,6 @@ final class SimpleAnnotationMetadata implements AnnotationMetadata {
return this.memberClassNames.clone();
}
@Override
public MergedAnnotations getAnnotations() {
return this.annotations;
}
@Override
public Set<String> getAnnotationTypes() {
Set<String> annotationTypes = this.annotationTypes;
@@ -154,9 +149,13 @@ final class SimpleAnnotationMetadata implements AnnotationMetadata {
annotatedMethods.add(annotatedMethod);
}
}
return (annotatedMethods != null ? annotatedMethods : Collections.emptySet());
return annotatedMethods != null ? annotatedMethods : Collections.emptySet();
}
@Override
public MergedAnnotations getAnnotations() {
return this.annotations;
}
@Override
public boolean equals(@Nullable Object obj) {
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -99,7 +99,8 @@ final class SimpleAnnotationMetadataReadingVisitor extends ClassVisitor {
}
@Override
public void visitInnerClass(String name, @Nullable String outerName, String innerName, int access) {
public void visitInnerClass(String name, @Nullable String outerName, String innerName,
int access) {
if (outerName != null) {
String className = toClassName(name);
String outerClassName = toClassName(outerName);
@@ -733,10 +733,6 @@ public class AntPathMatcher implements PathMatcher {
}
for (int i = 1; i <= matcher.groupCount(); i++) {
String name = this.variableNames.get(i - 1);
if (name.startsWith("*")) {
throw new IllegalArgumentException("Capturing patterns (" + name + ") are not " +
"supported by the AntPathMatcher. Use the PathPatternParser instead.");
}
String value = matcher.group(i);
uriTemplateVariables.put(name, value);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -71,8 +71,8 @@ class GenericTypeResolverTests {
void methodReturnTypes() {
assertThat(resolveReturnTypeArgument(findMethod(MyTypeWithMethods.class, "integer"), MyInterfaceType.class)).isEqualTo(Integer.class);
assertThat(resolveReturnTypeArgument(findMethod(MyTypeWithMethods.class, "string"), MyInterfaceType.class)).isEqualTo(String.class);
assertThat(resolveReturnTypeArgument(findMethod(MyTypeWithMethods.class, "raw"), MyInterfaceType.class)).isNull();
assertThat(resolveReturnTypeArgument(findMethod(MyTypeWithMethods.class, "object"), MyInterfaceType.class)).isNull();
assertThat(resolveReturnTypeArgument(findMethod(MyTypeWithMethods.class, "raw"), MyInterfaceType.class)).isEqualTo(null);
assertThat(resolveReturnTypeArgument(findMethod(MyTypeWithMethods.class, "object"), MyInterfaceType.class)).isEqualTo(null);
}
@Test
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -370,9 +370,9 @@ class ReactiveAdapterRegistryTests {
@Test
void deferred() {
assertThat(getAdapter(CompletableFuture.class).getDescriptor().isDeferred()).isFalse();
assertThat(getAdapter(Deferred.class).getDescriptor().isDeferred()).isTrue();
assertThat(getAdapter(kotlinx.coroutines.flow.Flow.class).getDescriptor().isDeferred()).isTrue();
assertThat(getAdapter(CompletableFuture.class).getDescriptor().isDeferred()).isEqualTo(false);
assertThat(getAdapter(Deferred.class).getDescriptor().isDeferred()).isEqualTo(true);
assertThat(getAdapter(kotlinx.coroutines.flow.Flow.class).getDescriptor().isDeferred()).isEqualTo(true);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -83,19 +83,19 @@ class ResolvableTypeTests {
assertThat(none.asMap()).isEqualTo(ResolvableType.NONE);
assertThat(none.getComponentType()).isEqualTo(ResolvableType.NONE);
assertThat(none.getGeneric(0)).isEqualTo(ResolvableType.NONE);
assertThat(none.getGenerics()).isEmpty();
assertThat(none.getInterfaces()).isEmpty();
assertThat(none.getGenerics().length).isEqualTo(0);
assertThat(none.getInterfaces().length).isEqualTo(0);
assertThat(none.getSuperType()).isEqualTo(ResolvableType.NONE);
assertThat(none.getType()).isEqualTo(ResolvableType.EmptyType.INSTANCE);
assertThat(none.hasGenerics()).isFalse();
assertThat(none.isArray()).isFalse();
assertThat(none.hasGenerics()).isEqualTo(false);
assertThat(none.isArray()).isEqualTo(false);
assertThat(none.resolve()).isNull();
assertThat(none.resolve(String.class)).isEqualTo(String.class);
assertThat(none.resolveGeneric(0)).isNull();
assertThat(none.resolveGenerics()).isEmpty();
assertThat(none.resolveGenerics().length).isEqualTo(0);
assertThat(none.toString()).isEqualTo("?");
assertThat(none.hasUnresolvableGenerics()).isFalse();
assertThat(none.isAssignableFrom(ResolvableType.forClass(Object.class))).isFalse();
assertThat(none.hasUnresolvableGenerics()).isEqualTo(false);
assertThat(none.isAssignableFrom(ResolvableType.forClass(Object.class))).isEqualTo(false);
}
@Test
@@ -148,9 +148,9 @@ class ResolvableTypeTests {
@Test
void forInstanceMustNotBeNull() throws Exception {
assertThatIllegalArgumentException()
.isThrownBy(() -> ResolvableType.forInstance(null))
.withMessage("Instance must not be null");
assertThatIllegalArgumentException().isThrownBy(() ->
ResolvableType.forInstance(null))
.withMessageContaining("Instance must not be null");
}
@Test
@@ -201,9 +201,9 @@ class ResolvableTypeTests {
@Test
void forFieldMustNotBeNull() throws Exception {
assertThatIllegalArgumentException()
.isThrownBy(() -> ResolvableType.forField(null))
.withMessage("Field must not be null");
assertThatIllegalArgumentException().isThrownBy(() ->
ResolvableType.forField(null))
.withMessageContaining("Field must not be null");
}
@Test
@@ -215,9 +215,9 @@ class ResolvableTypeTests {
@Test
void forConstructorParameterMustNotBeNull() throws Exception {
assertThatIllegalArgumentException()
.isThrownBy(() -> ResolvableType.forConstructorParameter(null, 0))
.withMessage("Constructor must not be null");
assertThatIllegalArgumentException().isThrownBy(() ->
ResolvableType.forConstructorParameter(null, 0))
.withMessageContaining("Constructor must not be null");
}
@Test
@@ -229,9 +229,9 @@ class ResolvableTypeTests {
@Test
void forMethodParameterByIndexMustNotBeNull() throws Exception {
assertThatIllegalArgumentException()
.isThrownBy(() -> ResolvableType.forMethodParameter(null, 0))
.withMessage("Method must not be null");
assertThatIllegalArgumentException().isThrownBy(() ->
ResolvableType.forMethodParameter(null, 0))
.withMessageContaining("Method must not be null");
}
@Test
@@ -269,9 +269,9 @@ class ResolvableTypeTests {
@Test
void forMethodParameterMustNotBeNull() throws Exception {
assertThatIllegalArgumentException()
.isThrownBy(() -> ResolvableType.forMethodParameter(null))
.withMessage("MethodParameter must not be null");
assertThatIllegalArgumentException().isThrownBy(() ->
ResolvableType.forMethodParameter(null))
.withMessageContaining("MethodParameter must not be null");
}
@Test // SPR-16210
@@ -296,9 +296,9 @@ class ResolvableTypeTests {
@Test
void forMethodReturnMustNotBeNull() throws Exception {
assertThatIllegalArgumentException()
.isThrownBy(() -> ResolvableType.forMethodReturnType(null))
.withMessage("Method must not be null");
assertThatIllegalArgumentException().isThrownBy(() ->
ResolvableType.forMethodReturnType(null))
.withMessageContaining("Method must not be null");
}
@Test
@@ -317,7 +317,7 @@ class ResolvableTypeTests {
void arrayClassType() throws Exception {
ResolvableType type = ResolvableType.forField(Fields.class.getField("arrayClassType"));
assertThat(type.getType()).isInstanceOf(Class.class);
assertThat(((Class) type.getType()).isArray()).isTrue();
assertThat(((Class) type.getType()).isArray()).isEqualTo(true);
}
@Test
@@ -343,7 +343,7 @@ class ResolvableTypeTests {
void getComponentTypeForClassArray() throws Exception {
Field field = Fields.class.getField("arrayClassType");
ResolvableType type = ResolvableType.forField(field);
assertThat(type.isArray()).isTrue();
assertThat(type.isArray()).isEqualTo(true);
assertThat(type.getComponentType().getType())
.isEqualTo(((Class) field.getGenericType()).getComponentType());
}
@@ -351,7 +351,7 @@ class ResolvableTypeTests {
@Test
void getComponentTypeForGenericArrayType() throws Exception {
ResolvableType type = ResolvableType.forField(Fields.class.getField("genericArrayType"));
assertThat(type.isArray()).isTrue();
assertThat(type.isArray()).isEqualTo(true);
assertThat(type.getComponentType().getType()).isEqualTo(
((GenericArrayType) type.getType()).getGenericComponentType());
}
@@ -359,7 +359,7 @@ class ResolvableTypeTests {
@Test
void getComponentTypeForVariableThatResolvesToGenericArray() throws Exception {
ResolvableType type = ResolvableType.forClass(ListOfGenericArray.class).asCollection().getGeneric();
assertThat(type.isArray()).isTrue();
assertThat(type.isArray()).isEqualTo(true);
assertThat(type.getType()).isInstanceOf(TypeVariable.class);
assertThat(type.getComponentType().getType().toString()).isEqualTo(
"java.util.List<java.lang.String>");
@@ -368,7 +368,7 @@ class ResolvableTypeTests {
@Test
void getComponentTypeForNonArray() throws Exception {
ResolvableType type = ResolvableType.forClass(String.class);
assertThat(type.isArray()).isFalse();
assertThat(type.isArray()).isEqualTo(false);
assertThat(type.getComponentType()).isEqualTo(ResolvableType.NONE);
}
@@ -438,7 +438,7 @@ class ResolvableTypeTests {
@Test
void getInterfaces() throws Exception {
ResolvableType type = ResolvableType.forClass(ExtendsList.class);
assertThat(type.getInterfaces()).isEmpty();
assertThat(type.getInterfaces().length).isEqualTo(0);
SortedSet<String> interfaces = new TreeSet<>();
for (ResolvableType interfaceType : type.getSuperType().getInterfaces()) {
interfaces.add(interfaceType.toString());
@@ -529,8 +529,8 @@ class ResolvableTypeTests {
@Test
void hasGenerics() throws Exception {
ResolvableType type = ResolvableType.forClass(ExtendsList.class);
assertThat(type.hasGenerics()).isFalse();
assertThat(type.asCollection().hasGenerics()).isTrue();
assertThat(type.hasGenerics()).isEqualTo(false);
assertThat(type.asCollection().hasGenerics()).isEqualTo(true);
}
@Test
@@ -553,7 +553,7 @@ class ResolvableTypeTests {
void noGetGenerics() throws Exception {
ResolvableType type = ResolvableType.forClass(ExtendsList.class);
ResolvableType[] generics = type.getGenerics();
assertThat(generics).isEmpty();
assertThat(generics.length).isEqualTo(0);
}
@Test
@@ -602,7 +602,7 @@ class ResolvableTypeTests {
ResolvableType type = ResolvableType.forField(Fields.class.getField("stringArrayList"));
ResolvableType generic = type.asCollection().getGeneric();
assertThat(generic.getType().toString()).isEqualTo("E");
assertThat(generic.isArray()).isTrue();
assertThat(generic.isArray()).isEqualTo(true);
assertThat(generic.resolve()).isEqualTo(String[].class);
}
@@ -610,7 +610,7 @@ class ResolvableTypeTests {
void resolveVariableGenericArray() throws Exception {
ResolvableType type = ResolvableType.forField(Fields.class.getField("variableTypeGenericArray"), TypedFields.class);
assertThat(type.getType().toString()).isEqualTo("T[]");
assertThat(type.isArray()).isTrue();
assertThat(type.isArray()).isEqualTo(true);
assertThat(type.resolve()).isEqualTo(String[].class);
}
@@ -618,7 +618,7 @@ class ResolvableTypeTests {
void resolveVariableGenericArrayUnknown() throws Exception {
ResolvableType type = ResolvableType.forField(Fields.class.getField("variableTypeGenericArray"));
assertThat(type.getType().toString()).isEqualTo("T[]");
assertThat(type.isArray()).isTrue();
assertThat(type.isArray()).isEqualTo(true);
assertThat(type.resolve()).isNull();
}
@@ -626,7 +626,7 @@ class ResolvableTypeTests {
void resolveVariableGenericArrayUnknownWithFallback() throws Exception {
ResolvableType type = ResolvableType.forField(Fields.class.getField("variableTypeGenericArray"));
assertThat(type.getType().toString()).isEqualTo("T[]");
assertThat(type.isArray()).isTrue();
assertThat(type.isArray()).isEqualTo(true);
assertThat(type.toClass()).isEqualTo(Object.class);
}
@@ -965,16 +965,16 @@ class ResolvableTypeTests {
@Test
void isAssignableFromMustNotBeNull() throws Exception {
assertThatIllegalArgumentException()
.isThrownBy(() -> ResolvableType.forClass(Object.class).isAssignableFrom((ResolvableType) null))
.withMessage("ResolvableType must not be null");
assertThatIllegalArgumentException().isThrownBy(() ->
ResolvableType.forClass(Object.class).isAssignableFrom((ResolvableType) null))
.withMessageContaining("Type must not be null");
}
@Test
void isAssignableFromForNone() throws Exception {
ResolvableType objectType = ResolvableType.forClass(Object.class);
assertThat(objectType.isAssignableFrom(ResolvableType.NONE)).isFalse();
assertThat(ResolvableType.NONE.isAssignableFrom(objectType)).isFalse();
assertThat(objectType.isAssignableFrom(ResolvableType.NONE)).isEqualTo(false);
assertThat(ResolvableType.NONE.isAssignableFrom(objectType)).isEqualTo(false);
}
@Test
@@ -1159,20 +1159,6 @@ class ResolvableTypeTests {
assertThatResolvableType(complex4).isNotAssignableFrom(complex3);
}
@Test
void identifyTypeVariable() throws Exception {
Method method = ClassArguments.class.getMethod("typedArgumentFirst", Class.class, Class.class, Class.class);
ResolvableType returnType = ResolvableType.forMethodReturnType(method, ClassArguments.class);
ResolvableType arg0 = ResolvableType.forMethodParameter(method, 0, ClassArguments.class);
ResolvableType arg1 = ResolvableType.forMethodParameter(method, 1, ClassArguments.class);
ResolvableType arg2 = ResolvableType.forMethodParameter(method, 2, ClassArguments.class);
assertThat(returnType.getType().equals(arg0.as(Class.class).getGeneric(0).getType())).isTrue();
assertThat(returnType.getType().equals(arg1.as(Class.class).getGeneric(0).getType())).isFalse();
assertThat(returnType.getType().equals(arg2.as(Class.class).getGeneric(0).getType())).isFalse();
}
@Test
void hashCodeAndEquals() throws Exception {
ResolvableType forClass = ResolvableType.forClass(List.class);
@@ -1221,10 +1207,9 @@ class ResolvableTypeTests {
@Test
void forClassWithMismatchedGenerics() throws Exception {
assertThatIllegalArgumentException()
.isThrownBy(() -> ResolvableType.forClassWithGenerics(Map.class, Integer.class))
.withMessageContaining("Mismatched number of generics specified for")
.withMessageContaining("java.util.Map<K,V>");
assertThatIllegalArgumentException().isThrownBy(() ->
ResolvableType.forClassWithGenerics(Map.class, Integer.class))
.withMessageContaining("Mismatched number of generics specified");
}
@Test
@@ -1263,19 +1248,19 @@ class ResolvableTypeTests {
@Test
void hasUnresolvableGenerics() throws Exception {
ResolvableType type = ResolvableType.forField(Fields.class.getField("stringList"));
assertThat(type.hasUnresolvableGenerics()).isFalse();
assertThat(type.hasUnresolvableGenerics()).isEqualTo(false);
}
@Test
void hasUnresolvableGenericsBasedOnOwnGenerics() throws Exception {
ResolvableType type = ResolvableType.forClass(List.class);
assertThat(type.hasUnresolvableGenerics()).isTrue();
assertThat(type.hasUnresolvableGenerics()).isEqualTo(true);
}
@Test
void hasUnresolvableGenericsWhenSelfNotResolvable() throws Exception {
ResolvableType type = ResolvableType.forClass(List.class).getGeneric();
assertThat(type.hasUnresolvableGenerics()).isFalse();
assertThat(type.hasUnresolvableGenerics()).isEqualTo(false);
}
@Test
@@ -1284,7 +1269,7 @@ class ResolvableTypeTests {
for (ResolvableType generic : type.getGenerics()) {
assertThat(generic.resolve()).isNotNull();
}
assertThat(type.hasUnresolvableGenerics()).isTrue();
assertThat(type.hasUnresolvableGenerics()).isEqualTo(true);
}
@Test
@@ -1293,7 +1278,7 @@ class ResolvableTypeTests {
for (ResolvableType generic : type.getGenerics()) {
assertThat(generic.resolve()).isNotNull();
}
assertThat(type.hasUnresolvableGenerics()).isTrue();
assertThat(type.hasUnresolvableGenerics()).isEqualTo(true);
}
@Test
@@ -1442,10 +1427,6 @@ class ResolvableTypeTests {
}
interface TypedMethods extends Methods<String> {
}
static class AssignmentBase<O, C, S> {
public O o;
@@ -1498,9 +1479,7 @@ class ResolvableTypeTests {
}
interface ClassArguments {
<T> T typedArgumentFirst(Class<T> arg0, Class<?> arg1, Class<Object> arg2);
interface TypedMethods extends Methods<String> {
}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -60,8 +60,8 @@ class AnnotationAttributesTests {
assertThat(attributes.getString("name")).isEqualTo("dave");
assertThat(attributes.getStringArray("names")).isEqualTo(new String[] {"dave", "frank", "hal"});
assertThat(attributes.getBoolean("bool1")).isTrue();
assertThat(attributes.getBoolean("bool2")).isFalse();
assertThat(attributes.getBoolean("bool1")).isEqualTo(true);
assertThat(attributes.getBoolean("bool2")).isEqualTo(false);
assertThat(attributes.<Color>getEnum("color")).isEqualTo(Color.RED);
assertThat(attributes.getClass("class").equals(Integer.class)).isTrue();
assertThat(attributes.getClassArray("classes")).isEqualTo(new Class<?>[] {Number.class, Short.class, Integer.class});

Some files were not shown because too many files have changed in this diff Show More