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 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -107,7 +107,7 @@ abstract class AbstractJCacheOperation<A extends Annotation> implements JCacheOp @@ -107,7 +107,7 @@ abstract class AbstractJCacheOperation<A extends Annotation> implements JCacheOp
}
@Override
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1113
public CacheInvocationParameter[] getAllParameters(@Nullable Object... values) {
if (this.allParameterDetails.size() != values.length) {
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 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -182,7 +182,7 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc @@ -182,7 +182,7 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc
}
}
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Dataflow analysis limitation
protected CacheManager getDefaultCacheManager() {
if (getCacheManager() == null) {
Assert.state(this.beanFactory != null, "BeanFactory required for default CacheManager resolution");
@ -202,7 +202,7 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc @@ -202,7 +202,7 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc
}
@Override
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Dataflow analysis limitation
protected CacheResolver getDefaultCacheResolver() {
if (getCacheResolver() == null) {
this.cacheResolver = SingletonSupplier.of(new SimpleCacheResolver(getDefaultCacheManager()));
@ -211,7 +211,7 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc @@ -211,7 +211,7 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc
}
@Override
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Dataflow analysis limitation
protected CacheResolver getDefaultExceptionCacheResolver() {
if (getExceptionCacheResolver() == null) {
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 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -84,7 +84,7 @@ class KeyGeneratorAdapter implements KeyGenerator { @@ -84,7 +84,7 @@ class KeyGeneratorAdapter implements KeyGenerator {
}
@Override
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1113
public Object generate(Object target, Method method, @Nullable Object... params) {
JCacheOperation<?> operation = this.cacheOperationSource.getCacheOperation(method, target.getClass());
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 { @@ -90,7 +90,7 @@ public class LocalDataSourceJobStore extends JobStoreCMT {
@Override
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Dataflow analysis limitation
public void initialize(ClassLoadHelper loadHelper, SchedulerSignaler signaler) throws SchedulerConfigException {
// Absolutely needs thread-bound DataSource to initialize.
this.dataSource = SchedulerFactoryBean.getConfigTimeDataSource();

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

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -194,7 +194,7 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware { @@ -194,7 +194,7 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
/**
* Register jobs and triggers (within a transaction, if possible).
*/
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Dataflow analysis limitation
protected void registerJobsAndTriggers() throws SchedulerException {
TransactionStatus transactionStatus = 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 @@ -644,7 +644,7 @@ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBe
* @see #afterPropertiesSet
* @see org.quartz.SchedulerFactory#getScheduler
*/
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Dataflow analysis limitation
protected Scheduler createScheduler(SchedulerFactory schedulerFactory, @Nullable String schedulerName)
throws SchedulerException {

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

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -43,7 +43,7 @@ import org.springframework.core.KotlinDetector; @@ -43,7 +43,7 @@ import org.springframework.core.KotlinDetector;
public class SimpleKeyGenerator implements KeyGenerator {
@Override
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1113
public Object generate(Object target, Method method, @Nullable Object... params) {
return generateKey((KotlinDetector.isSuspendingFunction(method) ?
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 { @@ -45,7 +45,7 @@ final class BeanMethod extends ConfigurationMethod {
@Override
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Reflection
public void validate(ProblemReporter problemReporter) {
if (getMetadata().getAnnotationAttributes(Autowired.class.getName()) != null) {
// 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 { @@ -218,7 +218,7 @@ final class ConfigurationClass {
return this.importBeanDefinitionRegistrars;
}
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Reflection
void validate(ProblemReporter problemReporter) {
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 { @@ -291,7 +291,7 @@ class ConfigurationClassBeanDefinitionReader {
this.registry.registerBeanDefinition(beanName, beanDefToRegister);
}
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Reflection
protected boolean isOverriddenByExistingDefinition(BeanMethod beanMethod, String beanName) {
if (!this.registry.containsBeanDefinition(beanName)) {
return false;

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

@ -821,12 +821,12 @@ class ConfigurationClassParser { @@ -821,12 +821,12 @@ class ConfigurationClassParser {
deferredImport.getConfigurationClass());
}
@SuppressWarnings("NullAway")
void processGroupImports() {
for (DeferredImportSelectorGrouping grouping : this.groupings.values()) {
Predicate<String> filter = grouping.getCandidateFilter();
grouping.getImports().forEach(entry -> {
ConfigurationClass configurationClass = this.configurationClasses.get(entry.getMetadata());
Assert.state(configurationClass != null, "ConfigurationClass must not be null");
try {
processImports(configurationClass, asSourceClass(configurationClass, 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 @@ -319,7 +319,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
}
@Override
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Lazy initialization
public @Nullable BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) {
boolean hasPropertySourceDescriptors = !CollectionUtils.isEmpty(this.propertySourceDescriptors);
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 @@ -127,7 +127,6 @@ public class ContextAnnotationAutowireCandidateResolver extends QualifierAnnotat
}
@Override
@SuppressWarnings("NullAway")
public Object getTarget() {
Object cachedTarget = this.cachedTarget;
if (cachedTarget != null) {

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

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -31,7 +31,7 @@ import org.springframework.util.MultiValueMap; @@ -31,7 +31,7 @@ import org.springframework.util.MultiValueMap;
class ProfileCondition implements Condition {
@Override
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Reflection
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
MultiValueMap<String, Object> attrs = metadata.getAllAnnotationAttributes(Profile.class.getName());
if (attrs != null) {

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

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -229,7 +229,7 @@ public abstract class AbstractApplicationEventMulticaster @@ -229,7 +229,7 @@ public abstract class AbstractApplicationEventMulticaster
* @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
*/
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Dataflow analysis limitation
private Collection<ApplicationListener<?>> retrieveApplicationListeners(
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; @@ -51,7 +51,7 @@ import org.springframework.format.annotation.DateTimeFormat.ISO;
* @see org.springframework.format.FormatterRegistrar#registerFormatters
* @see org.springframework.format.datetime.DateFormatterRegistrar
*/
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Well-known map keys
public class DateTimeFormatterRegistrar implements FormatterRegistrar {
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 @@ -987,7 +987,6 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
* Unregister the configured {@link NotificationListener NotificationListeners}
* from the {@link MBeanServer}.
*/
@SuppressWarnings("NullAway")
private void unregisterNotificationListeners() {
if (this.server != null) {
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 { @@ -669,7 +669,6 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
}
}
@SuppressWarnings("NullAway")
private void assertValidators(@Nullable Validator... validators) {
Object target = getTarget();
for (Validator validator : validators) {
@ -728,7 +727,6 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { @@ -728,7 +727,6 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
* {@link #setExcludedValidators(Predicate) exclude predicate}.
* @since 6.1
*/
@SuppressWarnings("NullAway")
public List<Validator> getValidatorsToApply() {
return (this.excludedValidators != null ?
this.validators.stream().filter(validator -> !this.excludedValidators.test(validator)).toList() :
@ -1232,7 +1230,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { @@ -1232,7 +1230,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
* @see #getBindingErrorProcessor
* @see BindingErrorProcessor#processMissingFieldError
*/
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Dataflow analysis limitation
protected void checkRequiredFields(MutablePropertyValues mpvs) {
String[] requiredFields = getRequiredFields();
if (!ObjectUtils.isEmpty(requiredFields)) {

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

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -243,7 +243,6 @@ public class DefaultMessageCodesResolver implements MessageCodesResolver, Serial @@ -243,7 +243,6 @@ public class DefaultMessageCodesResolver implements MessageCodesResolver, Serial
* {@link DefaultMessageCodesResolver#CODE_SEPARATOR}, skipping zero-length or
* null elements altogether.
*/
@SuppressWarnings("NullAway")
public static String toDelimitedString(@Nullable String... elements) {
StringJoiner rtn = new StringJoiner(CODE_SEPARATOR);
for (String element : elements) {

Loading…
Cancel
Save