diff --git a/gradle/spring-module.gradle b/gradle/spring-module.gradle index 47c2d66b3d..7596c4b39c 100644 --- a/gradle/spring-module.gradle +++ b/gradle/spring-module.gradle @@ -13,7 +13,7 @@ dependencies { jmh 'org.openjdk.jmh:jmh-generator-annprocess:1.37' jmh 'org.openjdk.jmh:jmh-generator-bytecode:1.37' jmh 'net.sf.jopt-simple:jopt-simple' - errorprone 'com.uber.nullaway:nullaway:0.12.3' + errorprone 'com.uber.nullaway:nullaway:0.12.4' errorprone 'com.google.errorprone:error_prone_core:2.36.0' } diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/config/AbstractJCacheConfiguration.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/config/AbstractJCacheConfiguration.java index dc31ac838f..6237426b73 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/config/AbstractJCacheConfiguration.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/config/AbstractJCacheConfiguration.java @@ -41,11 +41,11 @@ import org.springframework.context.annotation.Role; @Configuration(proxyBeanMethods = false) public abstract class AbstractJCacheConfiguration extends AbstractCachingConfiguration { - protected @Nullable Supplier exceptionCacheResolver; + protected @Nullable Supplier<@Nullable CacheResolver> exceptionCacheResolver; @Override - @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1126 + @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1128 protected void useCachingConfigurer(CachingConfigurerSupplier cachingConfigurerSupplier) { super.useCachingConfigurer(cachingConfigurerSupplier); this.exceptionCacheResolver = cachingConfigurerSupplier.adapt(config -> { diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultJCacheOperationSource.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultJCacheOperationSource.java index e71381f871..ed2a14e315 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultJCacheOperationSource.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultJCacheOperationSource.java @@ -79,8 +79,8 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc * @since 5.1 */ public DefaultJCacheOperationSource( - @Nullable Supplier cacheManager, @Nullable Supplier cacheResolver, - @Nullable Supplier exceptionCacheResolver, @Nullable Supplier keyGenerator) { + @Nullable Supplier<@Nullable CacheManager> cacheManager, @Nullable Supplier<@Nullable CacheResolver> cacheResolver, + @Nullable Supplier<@Nullable CacheResolver> exceptionCacheResolver, @Nullable Supplier<@Nullable KeyGenerator> keyGenerator) { this.cacheManager = SingletonSupplier.ofNullable(cacheManager); this.cacheResolver = SingletonSupplier.ofNullable(cacheResolver); diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/AbstractCachingConfiguration.java b/spring-context/src/main/java/org/springframework/cache/annotation/AbstractCachingConfiguration.java index b7939d7494..824773f892 100644 --- a/spring-context/src/main/java/org/springframework/cache/annotation/AbstractCachingConfiguration.java +++ b/spring-context/src/main/java/org/springframework/cache/annotation/AbstractCachingConfiguration.java @@ -50,13 +50,13 @@ public abstract class AbstractCachingConfiguration implements ImportAware { protected @Nullable AnnotationAttributes enableCaching; - protected @Nullable Supplier cacheManager; + protected @Nullable Supplier<@Nullable CacheManager> cacheManager; - protected @Nullable Supplier cacheResolver; + protected @Nullable Supplier<@Nullable CacheResolver> cacheResolver; - protected @Nullable Supplier keyGenerator; + protected @Nullable Supplier<@Nullable KeyGenerator> keyGenerator; - protected @Nullable Supplier errorHandler; + protected @Nullable Supplier<@Nullable CacheErrorHandler> errorHandler; @Override @@ -70,9 +70,8 @@ public abstract class AbstractCachingConfiguration implements ImportAware { } @Autowired - @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1126 void setConfigurers(ObjectProvider configurers) { - Supplier configurer = () -> { + Supplier<@Nullable CachingConfigurer> configurer = () -> { List candidates = configurers.stream().toList(); if (CollectionUtils.isEmpty(candidates)) { return null; @@ -91,7 +90,7 @@ public abstract class AbstractCachingConfiguration implements ImportAware { /** * Extract the configuration from the nominated {@link CachingConfigurer}. */ - @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1126 + @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1128 protected void useCachingConfigurer(CachingConfigurerSupplier cachingConfigurerSupplier) { this.cacheManager = cachingConfigurerSupplier.adapt(CachingConfigurer::cacheManager); this.cacheResolver = cachingConfigurerSupplier.adapt(CachingConfigurer::cacheResolver); @@ -104,7 +103,7 @@ public abstract class AbstractCachingConfiguration implements ImportAware { private final SingletonSupplier supplier; - public CachingConfigurerSupplier(Supplier supplier) { + public CachingConfigurerSupplier(Supplier<@Nullable CachingConfigurer> supplier) { this.supplier = SingletonSupplier.ofNullable(supplier); } @@ -117,7 +116,7 @@ public abstract class AbstractCachingConfiguration implements ImportAware { * @param the type of the supplier * @return another supplier mapped by the specified function */ - public Supplier<@Nullable T> adapt(Function provider) { + public Supplier<@Nullable T> adapt(Function provider) { return () -> { CachingConfigurer cachingConfigurer = this.supplier.get(); return (cachingConfigurer != null ? provider.apply(cachingConfigurer) : null); diff --git a/spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractReflectiveMBeanInfoAssembler.java b/spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractReflectiveMBeanInfoAssembler.java index 564a68f0e9..1f32cd256d 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractReflectiveMBeanInfoAssembler.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractReflectiveMBeanInfoAssembler.java @@ -506,7 +506,6 @@ public abstract class AbstractReflectiveMBeanInfoAssembler extends AbstractMBean * of the {@code MBeanExporter} * @return the {@code MBeanParameterInfo} array */ - @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1127 protected MBeanParameterInfo[] getOperationParameters(Method method, String beanKey) { ParameterNameDiscoverer paramNameDiscoverer = getParameterNameDiscoverer(); @Nullable String[] paramNames = (paramNameDiscoverer != null ? paramNameDiscoverer.getParameterNames(method) : null); diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/AbstractAsyncConfiguration.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/AbstractAsyncConfiguration.java index e0245db3da..b5b144210b 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/AbstractAsyncConfiguration.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/AbstractAsyncConfiguration.java @@ -67,7 +67,7 @@ public abstract class AbstractAsyncConfiguration implements ImportAware { * Collect any {@link AsyncConfigurer} beans through autowiring. */ @Autowired - @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1126 + @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1128 void setConfigurers(ObjectProvider configurers) { SingletonSupplier configurer = SingletonSupplier.ofNullable(() -> { List candidates = configurers.stream().toList(); diff --git a/spring-core/src/main/java/org/springframework/util/function/SingletonSupplier.java b/spring-core/src/main/java/org/springframework/util/function/SingletonSupplier.java index c5b2ef3752..9a7c59b15c 100644 --- a/spring-core/src/main/java/org/springframework/util/function/SingletonSupplier.java +++ b/spring-core/src/main/java/org/springframework/util/function/SingletonSupplier.java @@ -162,7 +162,7 @@ public class SingletonSupplier implements Supplier<@Nullable T> { * @return the singleton supplier, or {@code null} if the instance supplier was {@code null} */ @Contract("null -> null; !null -> !null") - public static @Nullable SingletonSupplier ofNullable(@Nullable Supplier supplier) { + public static @Nullable SingletonSupplier ofNullable(@Nullable Supplier<@Nullable T> supplier) { return (supplier != null ? new SingletonSupplier<>(supplier) : null); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceMethod.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceMethod.java index 36c59cce41..f15fa36790 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceMethod.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceMethod.java @@ -21,6 +21,7 @@ import java.time.Duration; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.function.Function; @@ -166,7 +167,7 @@ final class RSocketServiceMethod { ((Mono) responsePublisher).blockOptional()); } else { - return (blockTimeout != null ? + return Objects.requireNonNull(blockTimeout != null ? ((Mono) responsePublisher).block(blockTimeout) : ((Mono) responsePublisher).block()); } diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringSessionContext.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringSessionContext.java index d57ca19422..144d3f0c8c 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringSessionContext.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringSessionContext.java @@ -60,7 +60,7 @@ public class SpringSessionContext implements CurrentSessionContext { public SpringSessionContext(SessionFactoryImplementor sessionFactory) { this.sessionFactory = sessionFactory; try { - JtaPlatform jtaPlatform = sessionFactory.getServiceRegistry().getService(JtaPlatform.class); + JtaPlatform jtaPlatform = sessionFactory.getServiceRegistry().requireService(JtaPlatform.class); this.transactionManager = jtaPlatform.retrieveTransactionManager(); if (this.transactionManager != null) { this.jtaSessionContext = new SpringJtaSessionContext(sessionFactory); diff --git a/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java b/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java index 78fa9e2535..8bfdbdb7f0 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java @@ -20,6 +20,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Arrays; import java.util.Map; +import java.util.Objects; import kotlin.Unit; import kotlin.jvm.JvmClassMappingKt; @@ -317,7 +318,7 @@ public class InvocableHandlerMethod extends HandlerMethod { KType type = parameter.getType(); if (!(type.isMarkedNullable() && arg == null) && type.getClassifier() instanceof KClass kClass && KotlinDetector.isInlineClass(JvmClassMappingKt.getJavaClass(kClass))) { - KFunction constructor = KClasses.getPrimaryConstructor(kClass); + KFunction constructor = Objects.requireNonNull(KClasses.getPrimaryConstructor(kClass)); if (!KCallablesJvm.isAccessible(constructor)) { KCallablesJvm.setAccessible(constructor, true); } diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/AbstractReactorHttpExchangeAdapter.java b/spring-web/src/main/java/org/springframework/web/service/invoker/AbstractReactorHttpExchangeAdapter.java index 184a6e4a5e..4ab6c7bda3 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/AbstractReactorHttpExchangeAdapter.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/AbstractReactorHttpExchangeAdapter.java @@ -94,6 +94,7 @@ public abstract class AbstractReactorHttpExchangeAdapter implements ReactorHttpE } @Override + @Nullable public T exchangeForBody(HttpRequestValues requestValues, ParameterizedTypeReference bodyType) { return (this.blockTimeout != null ? exchangeForBodyMono(requestValues, bodyType).block(this.blockTimeout) : diff --git a/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java b/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java index 1826b78b10..6302f8d176 100644 --- a/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java +++ b/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java @@ -140,7 +140,6 @@ public class DefaultUriBuilderFactory implements UriBuilderFactory { * with a Map of variables. * @param defaultUriVariables default URI variable values */ - @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1126 public void setDefaultUriVariables(@Nullable Map defaultUriVariables) { if (defaultUriVariables != null) { if (this.defaultUriVariables == null) { @@ -432,7 +431,6 @@ public class DefaultUriBuilderFactory implements UriBuilderFactory { } @Override - @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1126 public URI build(Map uriVars) { if (!CollectionUtils.isEmpty(defaultUriVariables)) { Map map = new HashMap<>(defaultUriVariables.size() + uriVars.size()); @@ -448,7 +446,6 @@ public class DefaultUriBuilderFactory implements UriBuilderFactory { } @Override - @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1126 public URI build(@Nullable Object... uriVars) { if (ObjectUtils.isEmpty(uriVars) && !CollectionUtils.isEmpty(defaultUriVariables)) { return build(Collections.emptyMap()); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponse.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponse.java index c7cc077738..3c9c1c5145 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponse.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponse.java @@ -232,8 +232,7 @@ class DefaultClientResponse implements ClientResponse { }); } - @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1126 - private Function initDecodeFunction(byte[] body, @Nullable MediaType contentType) { + private Function initDecodeFunction(byte[] body, @Nullable MediaType contentType) { return targetType -> { if (ObjectUtils.isEmpty(body)) { return null; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/CompositeRequestCondition.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/CompositeRequestCondition.java index d3e4ce35d9..e3d297e52d 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/CompositeRequestCondition.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/CompositeRequestCondition.java @@ -92,7 +92,6 @@ public class CompositeRequestCondition extends AbstractRequestCondition getContent() { return (!isEmpty() ? getConditions() : Collections.emptyList()); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java index 086bdb28aa..59d6a848aa 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java @@ -23,6 +23,7 @@ import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Stream; import kotlin.Unit; @@ -355,7 +356,7 @@ public class InvocableHandlerMethod extends HandlerMethod { KType type = parameter.getType(); if (!(type.isMarkedNullable() && arg == null) && type.getClassifier() instanceof KClass kClass && KotlinDetector.isInlineClass(JvmClassMappingKt.getJavaClass(kClass))) { - KFunction constructor = KClasses.getPrimaryConstructor(kClass); + KFunction constructor = Objects.requireNonNull(KClasses.getPrimaryConstructor(kClass)); if (!KCallablesJvm.isAccessible(constructor)) { KCallablesJvm.setAccessible(constructor, true); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractNamedValueSyncArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractNamedValueSyncArgumentResolver.java index 7806237ee8..b956bdc55e 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractNamedValueSyncArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractNamedValueSyncArgumentResolver.java @@ -16,6 +16,8 @@ package org.springframework.web.reactive.result.method.annotation; +import java.util.Objects; + import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; @@ -69,7 +71,7 @@ public abstract class AbstractNamedValueSyncArgumentResolver extends AbstractNam MethodParameter parameter, BindingContext context, ServerWebExchange exchange) { // This won't block since resolveName below doesn't - return resolveArgument(parameter, context, exchange).block(); + return Objects.requireNonNull(resolveArgument(parameter, context, exchange).block()); } @Override