Use uppercase for classpath-related static final field names

Closes gh-35525
This commit is contained in:
Sébastien Deleuze
2025-09-22 17:59:49 +02:00
parent 5ac3c40689
commit 7635ac38f6
76 changed files with 451 additions and 450 deletions
@@ -50,14 +50,14 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl
"org.springframework.cache.aspectj.AspectJJCacheConfiguration";
private static final boolean jsr107Present;
private static final boolean JSR_107_PRESENT;
private static final boolean jcacheImplPresent;
private static final boolean JCACHE_IMPL_PRESENT;
static {
ClassLoader classLoader = CachingConfigurationSelector.class.getClassLoader();
jsr107Present = ClassUtils.isPresent("javax.cache.Cache", classLoader);
jcacheImplPresent = ClassUtils.isPresent(PROXY_JCACHE_CONFIGURATION_CLASS, classLoader);
JSR_107_PRESENT = ClassUtils.isPresent("javax.cache.Cache", classLoader);
JCACHE_IMPL_PRESENT = ClassUtils.isPresent(PROXY_JCACHE_CONFIGURATION_CLASS, classLoader);
}
@@ -82,7 +82,7 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl
List<String> result = new ArrayList<>(3);
result.add(AutoProxyRegistrar.class.getName());
result.add(ProxyCachingConfiguration.class.getName());
if (jsr107Present && jcacheImplPresent) {
if (JSR_107_PRESENT && JCACHE_IMPL_PRESENT) {
result.add(PROXY_JCACHE_CONFIGURATION_CLASS);
}
return StringUtils.toStringArray(result);
@@ -95,7 +95,7 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl
private String[] getAspectJImports() {
List<String> result = new ArrayList<>(2);
result.add(CACHE_ASPECT_CONFIGURATION_CLASS_NAME);
if (jsr107Present && jcacheImplPresent) {
if (JSR_107_PRESENT && JCACHE_IMPL_PRESENT) {
result.add(JCACHE_ASPECT_CONFIGURATION_CLASS_NAME);
}
return StringUtils.toStringArray(result);
@@ -61,14 +61,14 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
private static final String JCACHE_ASPECT_CLASS_NAME =
"org.springframework.cache.aspectj.JCacheCacheAspect";
private static final boolean jsr107Present;
private static final boolean JSR_107_PRESENT;
private static final boolean jcacheImplPresent;
private static final boolean JCACHE_IMPL_PRESENT;
static {
ClassLoader classLoader = AnnotationDrivenCacheBeanDefinitionParser.class.getClassLoader();
jsr107Present = ClassUtils.isPresent("javax.cache.Cache", classLoader);
jcacheImplPresent = ClassUtils.isPresent(
JSR_107_PRESENT = ClassUtils.isPresent("javax.cache.Cache", classLoader);
JCACHE_IMPL_PRESENT = ClassUtils.isPresent(
"org.springframework.cache.jcache.interceptor.DefaultJCacheOperationSource", classLoader);
}
@@ -95,7 +95,7 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
private void registerCacheAspect(Element element, ParserContext parserContext) {
SpringCachingConfigurer.registerCacheAspect(element, parserContext);
if (jsr107Present && jcacheImplPresent) {
if (JSR_107_PRESENT && JCACHE_IMPL_PRESENT) {
JCacheCachingConfigurer.registerCacheAspect(element, parserContext);
}
}
@@ -103,7 +103,7 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
private void registerCacheAdvisor(Element element, ParserContext parserContext) {
AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element);
SpringCachingConfigurer.registerCacheAdvisor(element, parserContext);
if (jsr107Present && jcacheImplPresent) {
if (JSR_107_PRESENT && JCACHE_IMPL_PRESENT) {
JCacheCachingConfigurer.registerCacheAdvisor(element, parserContext);
}
}
@@ -114,10 +114,10 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
*/
public static final String IGNORE_REACTIVESTREAMS_PROPERTY_NAME = "spring.cache.reactivestreams.ignore";
private static final boolean shouldIgnoreReactiveStreams =
private static final boolean SHOULD_IGNORE_REACTIVE_STREAMS =
SpringProperties.getFlag(IGNORE_REACTIVESTREAMS_PROPERTY_NAME);
private static final boolean reactiveStreamsPresent = ClassUtils.isPresent(
private static final boolean REACTIVE_STREAMS_PRESENT = ClassUtils.isPresent(
"org.reactivestreams.Publisher", CacheAspectSupport.class.getClassLoader());
@@ -145,7 +145,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
protected CacheAspectSupport() {
this.reactiveCachingHandler =
(reactiveStreamsPresent && !shouldIgnoreReactiveStreams ? new ReactiveCachingHandler() : null);
(REACTIVE_STREAMS_PRESENT && !SHOULD_IGNORE_REACTIVE_STREAMS ? new ReactiveCachingHandler() : null);
}
@@ -116,10 +116,10 @@ public abstract class AnnotationConfigUtils {
private static final ClassLoader classLoader = AnnotationConfigUtils.class.getClassLoader();
private static final boolean jakartaAnnotationsPresent =
private static final boolean JAKARTA_ANNOTATIONS_PRESENT =
ClassUtils.isPresent("jakarta.annotation.PostConstruct", classLoader);
private static final boolean jpaPresent =
private static final boolean JPA_PRESENT =
ClassUtils.isPresent("jakarta.persistence.EntityManagerFactory", classLoader) &&
ClassUtils.isPresent(PERSISTENCE_ANNOTATION_PROCESSOR_CLASS_NAME, classLoader);
@@ -168,14 +168,14 @@ public abstract class AnnotationConfigUtils {
}
// Check for Jakarta Annotations support, and if present add the CommonAnnotationBeanPostProcessor.
if (jakartaAnnotationsPresent && !registry.containsBeanDefinition(COMMON_ANNOTATION_PROCESSOR_BEAN_NAME)) {
if (JAKARTA_ANNOTATIONS_PRESENT && !registry.containsBeanDefinition(COMMON_ANNOTATION_PROCESSOR_BEAN_NAME)) {
RootBeanDefinition def = new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class);
def.setSource(source);
beanDefs.add(registerPostProcessor(registry, def, COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
}
// Check for JPA support, and if present add the PersistenceAnnotationBeanPostProcessor.
if (jpaPresent && !registry.containsBeanDefinition(PERSISTENCE_ANNOTATION_PROCESSOR_BEAN_NAME)) {
if (JPA_PRESENT && !registry.containsBeanDefinition(PERSISTENCE_ANNOTATION_PROCESSOR_BEAN_NAME)) {
RootBeanDefinition def = new RootBeanDefinition();
try {
def.setBeanClass(ClassUtils.forName(PERSISTENCE_ANNOTATION_PROCESSOR_CLASS_NAME,
@@ -142,24 +142,24 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
implements InstantiationAwareBeanPostProcessor, BeanFactoryAware, Serializable {
// Defensive reference to JNDI API for JDK 9+ (optional java.naming module)
private static final boolean jndiPresent = ClassUtils.isPresent(
private static final boolean JNDI_PRESENT = ClassUtils.isPresent(
"javax.naming.InitialContext", CommonAnnotationBeanPostProcessor.class.getClassLoader());
private static final Set<Class<? extends Annotation>> resourceAnnotationTypes = CollectionUtils.newLinkedHashSet(3);
private static final @Nullable Class<? extends Annotation> jakartaResourceType;
private static final @Nullable Class<? extends Annotation> JAKARTA_RESOURCE_TYPE;
private static final @Nullable Class<? extends Annotation> ejbAnnotationType;
private static final @Nullable Class<? extends Annotation> EJB_ANNOTATION_TYPE;
static {
jakartaResourceType = loadAnnotationType("jakarta.annotation.Resource");
if (jakartaResourceType != null) {
resourceAnnotationTypes.add(jakartaResourceType);
JAKARTA_RESOURCE_TYPE = loadAnnotationType("jakarta.annotation.Resource");
if (JAKARTA_RESOURCE_TYPE != null) {
resourceAnnotationTypes.add(JAKARTA_RESOURCE_TYPE);
}
ejbAnnotationType = loadAnnotationType("jakarta.ejb.EJB");
if (ejbAnnotationType != null) {
resourceAnnotationTypes.add(ejbAnnotationType);
EJB_ANNOTATION_TYPE = loadAnnotationType("jakarta.ejb.EJB");
if (EJB_ANNOTATION_TYPE != null) {
resourceAnnotationTypes.add(EJB_ANNOTATION_TYPE);
}
}
@@ -195,7 +195,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
addDestroyAnnotationType(loadAnnotationType("jakarta.annotation.PreDestroy"));
// java.naming module present on JDK 9+?
if (jndiPresent) {
if (JNDI_PRESENT) {
this.jndiFactory = new SimpleJndiBeanFactory();
}
}
@@ -405,13 +405,13 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
final List<InjectionMetadata.InjectedElement> currElements = new ArrayList<>();
ReflectionUtils.doWithLocalFields(targetClass, field -> {
if (ejbAnnotationType != null && field.isAnnotationPresent(ejbAnnotationType)) {
if (EJB_ANNOTATION_TYPE != null && field.isAnnotationPresent(EJB_ANNOTATION_TYPE)) {
if (Modifier.isStatic(field.getModifiers())) {
throw new IllegalStateException("@EJB annotation is not supported on static fields");
}
currElements.add(new EjbRefElement(field, field, null));
}
else if (jakartaResourceType != null && field.isAnnotationPresent(jakartaResourceType)) {
else if (JAKARTA_RESOURCE_TYPE != null && field.isAnnotationPresent(JAKARTA_RESOURCE_TYPE)) {
if (Modifier.isStatic(field.getModifiers())) {
throw new IllegalStateException("@Resource annotation is not supported on static fields");
}
@@ -426,7 +426,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
return;
}
if (ejbAnnotationType != null && bridgedMethod.isAnnotationPresent(ejbAnnotationType)) {
if (EJB_ANNOTATION_TYPE != null && bridgedMethod.isAnnotationPresent(EJB_ANNOTATION_TYPE)) {
if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
if (Modifier.isStatic(method.getModifiers())) {
throw new IllegalStateException("@EJB annotation is not supported on static methods");
@@ -438,7 +438,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
currElements.add(new EjbRefElement(method, bridgedMethod, pd));
}
}
else if (jakartaResourceType != null && bridgedMethod.isAnnotationPresent(jakartaResourceType)) {
else if (JAKARTA_RESOURCE_TYPE != null && bridgedMethod.isAnnotationPresent(JAKARTA_RESOURCE_TYPE)) {
if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
if (Modifier.isStatic(method.getModifiers())) {
throw new IllegalStateException("@Resource annotation is not supported on static methods");
@@ -74,7 +74,7 @@ import org.springframework.util.StringUtils;
*/
public class ApplicationListenerMethodAdapter implements GenericApplicationListener {
private static final boolean reactiveStreamsPresent = ClassUtils.isPresent(
private static final boolean REACTIVE_STREAMS_PRESENT = ClassUtils.isPresent(
"org.reactivestreams.Publisher", ApplicationListenerMethodAdapter.class.getClassLoader());
@@ -309,7 +309,7 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe
}
protected void handleResult(Object result) {
if (reactiveStreamsPresent && new ReactiveResultHandler().subscribeToPublisher(result)) {
if (REACTIVE_STREAMS_PRESENT && new ReactiveResultHandler().subscribeToPublisher(result)) {
if (logger.isTraceEnabled()) {
logger.trace("Adapted to reactive result: " + result);
}
@@ -47,11 +47,11 @@ import org.springframework.util.StringValueResolver;
*/
public class DefaultFormattingConversionService extends FormattingConversionService {
private static final boolean jsr354Present;
private static final boolean JSR_354_PRESENT;
static {
ClassLoader classLoader = DefaultFormattingConversionService.class.getClassLoader();
jsr354Present = ClassUtils.isPresent("javax.money.MonetaryAmount", classLoader);
JSR_354_PRESENT = ClassUtils.isPresent("javax.money.MonetaryAmount", classLoader);
}
/**
@@ -107,7 +107,7 @@ public class DefaultFormattingConversionService extends FormattingConversionServ
formatterRegistry.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory());
// Default handling of monetary values
if (jsr354Present) {
if (JSR_354_PRESENT) {
formatterRegistry.addFormatter(new CurrencyUnitFormatter());
formatterRegistry.addFormatter(new MonetaryAmountFormatter());
formatterRegistry.addFormatterForFieldAnnotation(new Jsr354NumberFormatAnnotationFormatterFactory());
@@ -51,14 +51,14 @@ public abstract class AbstractRetryInterceptor implements MethodInterceptor {
/**
* Reactive Streams API present on the classpath?
*/
private static final boolean reactiveStreamsPresent = ClassUtils.isPresent(
private static final boolean REACTIVE_STREAMS_PRESENT = ClassUtils.isPresent(
"org.reactivestreams.Publisher", AbstractRetryInterceptor.class.getClassLoader());
private final @Nullable ReactiveAdapterRegistry reactiveAdapterRegistry;
public AbstractRetryInterceptor() {
if (reactiveStreamsPresent) {
if (REACTIVE_STREAMS_PRESENT) {
this.reactiveAdapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
}
else {
@@ -127,7 +127,7 @@ public class ScheduledAnnotationBeanPostProcessor
/**
* Reactive Streams API present on the classpath?
*/
private static final boolean reactiveStreamsPresent = ClassUtils.isPresent(
private static final boolean REACTIVE_STREAMS_PRESENT = ClassUtils.isPresent(
"org.reactivestreams.Publisher", ScheduledAnnotationBeanPostProcessor.class.getClassLoader());
protected final Log logger = LogFactory.getLog(getClass());
@@ -330,7 +330,7 @@ public class ScheduledAnnotationBeanPostProcessor
protected void processScheduled(Scheduled scheduled, Method method, Object bean) {
// Is the method a Kotlin suspending function? Throws if true and the reactor bridge isn't on the classpath.
// Does the method return a reactive type? Throws if true and it isn't a deferred Publisher type.
if (reactiveStreamsPresent && ScheduledAnnotationReactiveSupport.isReactive(method)) {
if (REACTIVE_STREAMS_PRESENT && ScheduledAnnotationReactiveSupport.isReactive(method)) {
processScheduledAsync(scheduled, method, bean);
return;
}
@@ -60,10 +60,10 @@ import static org.springframework.scheduling.support.ScheduledTaskObservationDoc
*/
abstract class ScheduledAnnotationReactiveSupport {
static final boolean reactorPresent = ClassUtils.isPresent(
static final boolean REACTOR_PRESENT = ClassUtils.isPresent(
"reactor.core.publisher.Flux", ScheduledAnnotationReactiveSupport.class.getClassLoader());
static final boolean coroutinesReactorPresent = ClassUtils.isPresent(
static final boolean COROUTINES_REACTOR_PRESENT = ClassUtils.isPresent(
"kotlinx.coroutines.reactor.MonoKt", ScheduledAnnotationReactiveSupport.class.getClassLoader());
private static final Log logger = LogFactory.getLog(ScheduledAnnotationReactiveSupport.class);
@@ -87,7 +87,7 @@ abstract class ScheduledAnnotationReactiveSupport {
// parameter in reflective inspection
Assert.isTrue(method.getParameterCount() == 1,
"Kotlin suspending functions may only be annotated with @Scheduled if declared without arguments");
Assert.isTrue(coroutinesReactorPresent, "Kotlin suspending functions may only be annotated with " +
Assert.isTrue(COROUTINES_REACTOR_PRESENT, "Kotlin suspending functions may only be annotated with " +
"@Scheduled if the Coroutine-Reactor bridge (kotlinx.coroutines.reactor) is present at runtime");
return true;
}
@@ -161,7 +161,7 @@ abstract class ScheduledAnnotationReactiveSupport {
Publisher<?> publisher = adapter.toPublisher(returnValue);
// If Reactor is on the classpath, we could benefit from having a checkpoint for debuggability
if (reactorPresent) {
if (REACTOR_PRESENT) {
return Flux.from(publisher).checkpoint(
"@Scheduled '"+ method.getName() + "()' in '" + method.getDeclaringClass().getName() + "'");
}
@@ -246,7 +246,7 @@ abstract class ScheduledAnnotationReactiveSupport {
private void subscribe(TrackingSubscriber subscriber, Observation observation) {
this.subscriptionTrackerRegistry.add(subscriber);
if (reactorPresent) {
if (REACTOR_PRESENT) {
observation.start();
Flux.from(this.publisher)
.contextWrite(context -> context.put(ObservationThreadLocalAccessor.KEY, observation))
@@ -61,7 +61,7 @@ import org.springframework.util.ReflectionUtils;
*/
class BeanValidationBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor {
private static final boolean beanValidationPresent = ClassUtils.isPresent(
private static final boolean BEAN_VALIDATION_PRESENT = ClassUtils.isPresent(
"jakarta.validation.Validation", BeanValidationBeanRegistrationAotProcessor.class.getClassLoader());
private static final Log logger = LogFactory.getLog(BeanValidationBeanRegistrationAotProcessor.class);
@@ -69,7 +69,7 @@ class BeanValidationBeanRegistrationAotProcessor implements BeanRegistrationAotP
@Override
public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
if (beanValidationPresent) {
if (BEAN_VALIDATION_PRESENT) {
return BeanValidationDelegate.processAheadOfTime(registeredBean);
}
return null;
@@ -79,7 +79,7 @@ import org.springframework.validation.method.ParameterValidationResult;
*/
public class MethodValidationInterceptor implements MethodInterceptor {
private static final boolean reactorPresent = ClassUtils.isPresent(
private static final boolean REACTOR_PRESENT = ClassUtils.isPresent(
"reactor.core.publisher.Mono", MethodValidationInterceptor.class.getClassLoader());
@@ -152,7 +152,7 @@ public class MethodValidationInterceptor implements MethodInterceptor {
@Nullable Object[] arguments = invocation.getArguments();
Class<?>[] groups = determineValidationGroups(invocation);
if (reactorPresent) {
if (REACTOR_PRESENT) {
arguments = ReactorValidationHelper.insertAsyncValidation(
this.validationAdapter.getSpringValidatorAdapter(), this.adaptViolations,
target, method, arguments);