Skip to content

Commit

Permalink
Refine null-safety in the spring-context module
Browse files Browse the repository at this point in the history
  • Loading branch information
sdeleuze committed Dec 24, 2024
1 parent cf90bee commit f368147
Show file tree
Hide file tree
Showing 19 changed files with 26 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -107,7 +107,7 @@ public CacheResolver getCacheResolver() {
}

@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 " +
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -182,7 +182,7 @@ protected <T> T getBean(Class<T> type) {
}
}

@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Dataflow analysis limitation
protected CacheManager getDefaultCacheManager() {
if (getCacheManager() == null) {
Assert.state(this.beanFactory != null, "BeanFactory required for default CacheManager resolution");
Expand All @@ -202,7 +202,7 @@ protected CacheManager getDefaultCacheManager() {
}

@Override
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Dataflow analysis limitation
protected CacheResolver getDefaultCacheResolver() {
if (getCacheResolver() == null) {
this.cacheResolver = SingletonSupplier.of(new SimpleCacheResolver(getDefaultCacheManager()));
Expand All @@ -211,7 +211,7 @@ protected CacheResolver getDefaultCacheResolver() {
}

@Override
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Dataflow analysis limitation
protected CacheResolver getDefaultExceptionCacheResolver() {
if (getExceptionCacheResolver() == null) {
this.exceptionCacheResolver = SingletonSupplier.of(new LazyCacheResolver());
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -84,7 +84,7 @@ public Object getTarget() {
}

@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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -194,7 +194,7 @@ public void setResourceLoader(ResourceLoader resourceLoader) {
/**
* 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ private Scheduler prepareScheduler(SchedulerFactory schedulerFactory) throws Sch
* @see #afterPropertiesSet
* @see org.quartz.SchedulerFactory#getScheduler
*/
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Dataflow analysis limitation
protected Scheduler createScheduler(SchedulerFactory schedulerFactory, @Nullable String schedulerName)
throws SchedulerException {

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -43,7 +43,7 @@
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ Map<ImportBeanDefinitionRegistrar, AnnotationMetadata> getImportBeanDefinitionRe
return this.importBeanDefinitionRegistrars;
}

@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Reflection
void validate(ProblemReporter problemReporter) {
Map<String, Object> attributes = this.metadata.getAnnotationAttributes(Configuration.class.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private void loadBeanDefinitionsForBeanMethod(BeanMethod beanMethod) {
this.registry.registerBeanDefinition(beanName, beanDefToRegister);
}

@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Reflection
protected boolean isOverriddenByExistingDefinition(BeanMethod beanMethod, String beanName) {
if (!this.registry.containsBeanDefinition(beanName)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -821,12 +821,12 @@ void register(DeferredImportSelectorHolder deferredImport) {
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)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
}

@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ public Class<?> getTargetClass() {
}

@Override
@SuppressWarnings("NullAway")
public Object getTarget() {
Object cachedTarget = this.cachedTarget;
if (cachedTarget != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -31,7 +31,7 @@
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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -229,7 +229,7 @@ protected Collection<ApplicationListener<?>> getApplicationListeners(
* @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) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
* @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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,6 @@ private void registerNotificationListeners() throws MBeanExportException {
* Unregister the configured {@link NotificationListener NotificationListeners}
* from the {@link MBeanServer}.
*/
@SuppressWarnings("NullAway")
private void unregisterNotificationListeners() {
if (this.server != null) {
this.registeredNotificationListeners.forEach((bean, mappedObjectNames) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,6 @@ public void setValidator(@Nullable Validator validator) {
}
}

@SuppressWarnings("NullAway")
private void assertValidators(@Nullable Validator... validators) {
Object target = getTarget();
for (Validator validator : validators) {
Expand Down Expand Up @@ -728,7 +727,6 @@ public List<Validator> getValidators() {
* {@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() :
Expand Down Expand Up @@ -1232,7 +1230,7 @@ protected boolean isAllowed(String field) {
* @see #getBindingErrorProcessor
* @see BindingErrorProcessor#processMissingFieldError
*/
@SuppressWarnings("NullAway")
@SuppressWarnings("NullAway") // Dataflow analysis limitation
protected void checkRequiredFields(MutablePropertyValues mpvs) {
String[] requiredFields = getRequiredFields();
if (!ObjectUtils.isEmpty(requiredFields)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -243,7 +243,6 @@ public String format(String errorCode, @Nullable String objectName, @Nullable St
* {@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) {
Expand Down

0 comments on commit f368147

Please sign in to comment.