Browse Source

Refine null-safety in the spring-context module

Closes gh-34151
pull/34171/head
Sébastien Deleuze 12 months ago
parent
commit
f368147f9d
  1. 4
      spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractJCacheOperation.java
  2. 8
      spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultJCacheOperationSource.java
  3. 4
      spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/KeyGeneratorAdapter.java
  4. 2
      spring-context-support/src/main/java/org/springframework/scheduling/quartz/LocalDataSourceJobStore.java
  5. 4
      spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java
  6. 2
      spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java
  7. 4
      spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKeyGenerator.java
  8. 2
      spring-context/src/main/java/org/springframework/context/annotation/BeanMethod.java
  9. 2
      spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClass.java
  10. 2
      spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java
  11. 2
      spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java
  12. 2
      spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java
  13. 1
      spring-context/src/main/java/org/springframework/context/annotation/ContextAnnotationAutowireCandidateResolver.java
  14. 4
      spring-context/src/main/java/org/springframework/context/annotation/ProfileCondition.java
  15. 4
      spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java
  16. 2
      spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeFormatterRegistrar.java
  17. 1
      spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java
  18. 4
      spring-context/src/main/java/org/springframework/validation/DataBinder.java
  19. 3
      spring-context/src/main/java/org/springframework/validation/DefaultMessageCodesResolver.java

4
spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractJCacheOperation.java vendored

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -107,7 +107,7 @@ abstract class AbstractJCacheOperation<A extends Annotation> implements JCacheOp
} }
@Override @Override
@SuppressWarnings("NullAway") @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1113
public CacheInvocationParameter[] getAllParameters(@Nullable Object... values) { public CacheInvocationParameter[] getAllParameters(@Nullable Object... values) {
if (this.allParameterDetails.size() != values.length) { if (this.allParameterDetails.size() != values.length) {
throw new IllegalStateException("Values mismatch, operation has " + throw new IllegalStateException("Values mismatch, operation has " +

8
spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultJCacheOperationSource.java vendored

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -182,7 +182,7 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc
} }
} }
@SuppressWarnings("NullAway") @SuppressWarnings("NullAway") // Dataflow analysis limitation
protected CacheManager getDefaultCacheManager() { protected CacheManager getDefaultCacheManager() {
if (getCacheManager() == null) { if (getCacheManager() == null) {
Assert.state(this.beanFactory != null, "BeanFactory required for default CacheManager resolution"); Assert.state(this.beanFactory != null, "BeanFactory required for default CacheManager resolution");
@ -202,7 +202,7 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc
} }
@Override @Override
@SuppressWarnings("NullAway") @SuppressWarnings("NullAway") // Dataflow analysis limitation
protected CacheResolver getDefaultCacheResolver() { protected CacheResolver getDefaultCacheResolver() {
if (getCacheResolver() == null) { if (getCacheResolver() == null) {
this.cacheResolver = SingletonSupplier.of(new SimpleCacheResolver(getDefaultCacheManager())); this.cacheResolver = SingletonSupplier.of(new SimpleCacheResolver(getDefaultCacheManager()));
@ -211,7 +211,7 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc
} }
@Override @Override
@SuppressWarnings("NullAway") @SuppressWarnings("NullAway") // Dataflow analysis limitation
protected CacheResolver getDefaultExceptionCacheResolver() { protected CacheResolver getDefaultExceptionCacheResolver() {
if (getExceptionCacheResolver() == null) { if (getExceptionCacheResolver() == null) {
this.exceptionCacheResolver = SingletonSupplier.of(new LazyCacheResolver()); this.exceptionCacheResolver = SingletonSupplier.of(new LazyCacheResolver());

4
spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/KeyGeneratorAdapter.java vendored

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -84,7 +84,7 @@ class KeyGeneratorAdapter implements KeyGenerator {
} }
@Override @Override
@SuppressWarnings("NullAway") @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1113
public Object generate(Object target, Method method, @Nullable Object... params) { public Object generate(Object target, Method method, @Nullable Object... params) {
JCacheOperation<?> operation = this.cacheOperationSource.getCacheOperation(method, target.getClass()); JCacheOperation<?> operation = this.cacheOperationSource.getCacheOperation(method, target.getClass());
if (!(operation instanceof AbstractJCacheKeyOperation)) { if (!(operation instanceof AbstractJCacheKeyOperation)) {

2
spring-context-support/src/main/java/org/springframework/scheduling/quartz/LocalDataSourceJobStore.java

@ -90,7 +90,7 @@ public class LocalDataSourceJobStore extends JobStoreCMT {
@Override @Override
@SuppressWarnings("NullAway") @SuppressWarnings("NullAway") // Dataflow analysis limitation
public void initialize(ClassLoadHelper loadHelper, SchedulerSignaler signaler) throws SchedulerConfigException { public void initialize(ClassLoadHelper loadHelper, SchedulerSignaler signaler) throws SchedulerConfigException {
// Absolutely needs thread-bound DataSource to initialize. // Absolutely needs thread-bound DataSource to initialize.
this.dataSource = SchedulerFactoryBean.getConfigTimeDataSource(); this.dataSource = SchedulerFactoryBean.getConfigTimeDataSource();

4
spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -194,7 +194,7 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
/** /**
* Register jobs and triggers (within a transaction, if possible). * Register jobs and triggers (within a transaction, if possible).
*/ */
@SuppressWarnings("NullAway") @SuppressWarnings("NullAway") // Dataflow analysis limitation
protected void registerJobsAndTriggers() throws SchedulerException { protected void registerJobsAndTriggers() throws SchedulerException {
TransactionStatus transactionStatus = null; TransactionStatus transactionStatus = null;
if (this.transactionManager != null) { if (this.transactionManager != null) {

2
spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java

@ -644,7 +644,7 @@ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBe
* @see #afterPropertiesSet * @see #afterPropertiesSet
* @see org.quartz.SchedulerFactory#getScheduler * @see org.quartz.SchedulerFactory#getScheduler
*/ */
@SuppressWarnings("NullAway") @SuppressWarnings("NullAway") // Dataflow analysis limitation
protected Scheduler createScheduler(SchedulerFactory schedulerFactory, @Nullable String schedulerName) protected Scheduler createScheduler(SchedulerFactory schedulerFactory, @Nullable String schedulerName)
throws SchedulerException { throws SchedulerException {

4
spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKeyGenerator.java vendored

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -43,7 +43,7 @@ import org.springframework.core.KotlinDetector;
public class SimpleKeyGenerator implements KeyGenerator { public class SimpleKeyGenerator implements KeyGenerator {
@Override @Override
@SuppressWarnings("NullAway") @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1113
public Object generate(Object target, Method method, @Nullable Object... params) { public Object generate(Object target, Method method, @Nullable Object... params) {
return generateKey((KotlinDetector.isSuspendingFunction(method) ? return generateKey((KotlinDetector.isSuspendingFunction(method) ?
Arrays.copyOf(params, params.length - 1) : params)); Arrays.copyOf(params, params.length - 1) : params));

2
spring-context/src/main/java/org/springframework/context/annotation/BeanMethod.java

@ -45,7 +45,7 @@ final class BeanMethod extends ConfigurationMethod {
@Override @Override
@SuppressWarnings("NullAway") @SuppressWarnings("NullAway") // Reflection
public void validate(ProblemReporter problemReporter) { public void validate(ProblemReporter problemReporter) {
if (getMetadata().getAnnotationAttributes(Autowired.class.getName()) != null) { if (getMetadata().getAnnotationAttributes(Autowired.class.getName()) != null) {
// declared as @Autowired: semantic mismatch since @Bean method arguments are autowired // declared as @Autowired: semantic mismatch since @Bean method arguments are autowired

2
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClass.java

@ -218,7 +218,7 @@ final class ConfigurationClass {
return this.importBeanDefinitionRegistrars; return this.importBeanDefinitionRegistrars;
} }
@SuppressWarnings("NullAway") @SuppressWarnings("NullAway") // Reflection
void validate(ProblemReporter problemReporter) { void validate(ProblemReporter problemReporter) {
Map<String, Object> attributes = this.metadata.getAnnotationAttributes(Configuration.class.getName()); Map<String, Object> attributes = this.metadata.getAnnotationAttributes(Configuration.class.getName());

2
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java

@ -291,7 +291,7 @@ class ConfigurationClassBeanDefinitionReader {
this.registry.registerBeanDefinition(beanName, beanDefToRegister); this.registry.registerBeanDefinition(beanName, beanDefToRegister);
} }
@SuppressWarnings("NullAway") @SuppressWarnings("NullAway") // Reflection
protected boolean isOverriddenByExistingDefinition(BeanMethod beanMethod, String beanName) { protected boolean isOverriddenByExistingDefinition(BeanMethod beanMethod, String beanName) {
if (!this.registry.containsBeanDefinition(beanName)) { if (!this.registry.containsBeanDefinition(beanName)) {
return false; return false;

2
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java

@ -821,12 +821,12 @@ class ConfigurationClassParser {
deferredImport.getConfigurationClass()); deferredImport.getConfigurationClass());
} }
@SuppressWarnings("NullAway")
void processGroupImports() { void processGroupImports() {
for (DeferredImportSelectorGrouping grouping : this.groupings.values()) { for (DeferredImportSelectorGrouping grouping : this.groupings.values()) {
Predicate<String> filter = grouping.getCandidateFilter(); Predicate<String> filter = grouping.getCandidateFilter();
grouping.getImports().forEach(entry -> { grouping.getImports().forEach(entry -> {
ConfigurationClass configurationClass = this.configurationClasses.get(entry.getMetadata()); ConfigurationClass configurationClass = this.configurationClasses.get(entry.getMetadata());
Assert.state(configurationClass != null, "ConfigurationClass must not be null");
try { try {
processImports(configurationClass, asSourceClass(configurationClass, filter), processImports(configurationClass, asSourceClass(configurationClass, filter),
Collections.singleton(asSourceClass(entry.getImportClassName(), filter)), Collections.singleton(asSourceClass(entry.getImportClassName(), filter)),

2
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java

@ -319,7 +319,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
} }
@Override @Override
@SuppressWarnings("NullAway") @SuppressWarnings("NullAway") // Lazy initialization
public @Nullable BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) { public @Nullable BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) {
boolean hasPropertySourceDescriptors = !CollectionUtils.isEmpty(this.propertySourceDescriptors); boolean hasPropertySourceDescriptors = !CollectionUtils.isEmpty(this.propertySourceDescriptors);
boolean hasImportRegistry = beanFactory.containsBean(IMPORT_REGISTRY_BEAN_NAME); boolean hasImportRegistry = beanFactory.containsBean(IMPORT_REGISTRY_BEAN_NAME);

1
spring-context/src/main/java/org/springframework/context/annotation/ContextAnnotationAutowireCandidateResolver.java

@ -127,7 +127,6 @@ public class ContextAnnotationAutowireCandidateResolver extends QualifierAnnotat
} }
@Override @Override
@SuppressWarnings("NullAway")
public Object getTarget() { public Object getTarget() {
Object cachedTarget = this.cachedTarget; Object cachedTarget = this.cachedTarget;
if (cachedTarget != null) { if (cachedTarget != null) {

4
spring-context/src/main/java/org/springframework/context/annotation/ProfileCondition.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,7 +31,7 @@ import org.springframework.util.MultiValueMap;
class ProfileCondition implements Condition { class ProfileCondition implements Condition {
@Override @Override
@SuppressWarnings("NullAway") @SuppressWarnings("NullAway") // Reflection
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
MultiValueMap<String, Object> attrs = metadata.getAllAnnotationAttributes(Profile.class.getName()); MultiValueMap<String, Object> attrs = metadata.getAllAnnotationAttributes(Profile.class.getName());
if (attrs != null) { if (attrs != null) {

4
spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -229,7 +229,7 @@ public abstract class AbstractApplicationEventMulticaster
* @param retriever the ListenerRetriever, if supposed to populate one (for caching purposes) * @param retriever the ListenerRetriever, if supposed to populate one (for caching purposes)
* @return the pre-filtered list of application listeners for the given event and source type * @return the pre-filtered list of application listeners for the given event and source type
*/ */
@SuppressWarnings("NullAway") @SuppressWarnings("NullAway") // Dataflow analysis limitation
private Collection<ApplicationListener<?>> retrieveApplicationListeners( private Collection<ApplicationListener<?>> retrieveApplicationListeners(
ResolvableType eventType, @Nullable Class<?> sourceType, @Nullable CachedListenerRetriever retriever) { ResolvableType eventType, @Nullable Class<?> sourceType, @Nullable CachedListenerRetriever retriever) {

2
spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeFormatterRegistrar.java

@ -51,7 +51,7 @@ import org.springframework.format.annotation.DateTimeFormat.ISO;
* @see org.springframework.format.FormatterRegistrar#registerFormatters * @see org.springframework.format.FormatterRegistrar#registerFormatters
* @see org.springframework.format.datetime.DateFormatterRegistrar * @see org.springframework.format.datetime.DateFormatterRegistrar
*/ */
@SuppressWarnings("NullAway") @SuppressWarnings("NullAway") // Well-known map keys
public class DateTimeFormatterRegistrar implements FormatterRegistrar { public class DateTimeFormatterRegistrar implements FormatterRegistrar {
private enum Type {DATE, TIME, DATE_TIME} private enum Type {DATE, TIME, DATE_TIME}

1
spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java

@ -987,7 +987,6 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
* Unregister the configured {@link NotificationListener NotificationListeners} * Unregister the configured {@link NotificationListener NotificationListeners}
* from the {@link MBeanServer}. * from the {@link MBeanServer}.
*/ */
@SuppressWarnings("NullAway")
private void unregisterNotificationListeners() { private void unregisterNotificationListeners() {
if (this.server != null) { if (this.server != null) {
this.registeredNotificationListeners.forEach((bean, mappedObjectNames) -> { this.registeredNotificationListeners.forEach((bean, mappedObjectNames) -> {

4
spring-context/src/main/java/org/springframework/validation/DataBinder.java

@ -669,7 +669,6 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
} }
} }
@SuppressWarnings("NullAway")
private void assertValidators(@Nullable Validator... validators) { private void assertValidators(@Nullable Validator... validators) {
Object target = getTarget(); Object target = getTarget();
for (Validator validator : validators) { for (Validator validator : validators) {
@ -728,7 +727,6 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
* {@link #setExcludedValidators(Predicate) exclude predicate}. * {@link #setExcludedValidators(Predicate) exclude predicate}.
* @since 6.1 * @since 6.1
*/ */
@SuppressWarnings("NullAway")
public List<Validator> getValidatorsToApply() { public List<Validator> getValidatorsToApply() {
return (this.excludedValidators != null ? return (this.excludedValidators != null ?
this.validators.stream().filter(validator -> !this.excludedValidators.test(validator)).toList() : this.validators.stream().filter(validator -> !this.excludedValidators.test(validator)).toList() :
@ -1232,7 +1230,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
* @see #getBindingErrorProcessor * @see #getBindingErrorProcessor
* @see BindingErrorProcessor#processMissingFieldError * @see BindingErrorProcessor#processMissingFieldError
*/ */
@SuppressWarnings("NullAway") @SuppressWarnings("NullAway") // Dataflow analysis limitation
protected void checkRequiredFields(MutablePropertyValues mpvs) { protected void checkRequiredFields(MutablePropertyValues mpvs) {
String[] requiredFields = getRequiredFields(); String[] requiredFields = getRequiredFields();
if (!ObjectUtils.isEmpty(requiredFields)) { if (!ObjectUtils.isEmpty(requiredFields)) {

3
spring-context/src/main/java/org/springframework/validation/DefaultMessageCodesResolver.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -243,7 +243,6 @@ public class DefaultMessageCodesResolver implements MessageCodesResolver, Serial
* {@link DefaultMessageCodesResolver#CODE_SEPARATOR}, skipping zero-length or * {@link DefaultMessageCodesResolver#CODE_SEPARATOR}, skipping zero-length or
* null elements altogether. * null elements altogether.
*/ */
@SuppressWarnings("NullAway")
public static String toDelimitedString(@Nullable String... elements) { public static String toDelimitedString(@Nullable String... elements) {
StringJoiner rtn = new StringJoiner(CODE_SEPARATOR); StringJoiner rtn = new StringJoiner(CODE_SEPARATOR);
for (String element : elements) { for (String element : elements) {

Loading…
Cancel
Save