Upgrade NullAway to 0.12.4

This commit also slightly refines nullness but without
significant user-side impact expected.

Closes gh-34525
This commit is contained in:
Sébastien Deleuze 2025-03-03 08:43:34 +01:00
parent f7db4bf4f0
commit 7bc712e304
16 changed files with 27 additions and 28 deletions

View File

@ -13,7 +13,7 @@ dependencies {
jmh 'org.openjdk.jmh:jmh-generator-annprocess:1.37' jmh 'org.openjdk.jmh:jmh-generator-annprocess:1.37'
jmh 'org.openjdk.jmh:jmh-generator-bytecode:1.37' jmh 'org.openjdk.jmh:jmh-generator-bytecode:1.37'
jmh 'net.sf.jopt-simple:jopt-simple' 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' errorprone 'com.google.errorprone:error_prone_core:2.36.0'
} }

View File

@ -41,11 +41,11 @@ import org.springframework.context.annotation.Role;
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
public abstract class AbstractJCacheConfiguration extends AbstractCachingConfiguration { public abstract class AbstractJCacheConfiguration extends AbstractCachingConfiguration {
protected @Nullable Supplier<? extends @Nullable CacheResolver> exceptionCacheResolver; protected @Nullable Supplier<@Nullable CacheResolver> exceptionCacheResolver;
@Override @Override
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1126 @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1128
protected void useCachingConfigurer(CachingConfigurerSupplier cachingConfigurerSupplier) { protected void useCachingConfigurer(CachingConfigurerSupplier cachingConfigurerSupplier) {
super.useCachingConfigurer(cachingConfigurerSupplier); super.useCachingConfigurer(cachingConfigurerSupplier);
this.exceptionCacheResolver = cachingConfigurerSupplier.adapt(config -> { this.exceptionCacheResolver = cachingConfigurerSupplier.adapt(config -> {

View File

@ -79,8 +79,8 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc
* @since 5.1 * @since 5.1
*/ */
public DefaultJCacheOperationSource( public DefaultJCacheOperationSource(
@Nullable Supplier<? extends @Nullable CacheManager> cacheManager, @Nullable Supplier<? extends @Nullable CacheResolver> cacheResolver, @Nullable Supplier<@Nullable CacheManager> cacheManager, @Nullable Supplier<@Nullable CacheResolver> cacheResolver,
@Nullable Supplier<? extends @Nullable CacheResolver> exceptionCacheResolver, @Nullable Supplier<? extends @Nullable KeyGenerator> keyGenerator) { @Nullable Supplier<@Nullable CacheResolver> exceptionCacheResolver, @Nullable Supplier<@Nullable KeyGenerator> keyGenerator) {
this.cacheManager = SingletonSupplier.ofNullable(cacheManager); this.cacheManager = SingletonSupplier.ofNullable(cacheManager);
this.cacheResolver = SingletonSupplier.ofNullable(cacheResolver); this.cacheResolver = SingletonSupplier.ofNullable(cacheResolver);

View File

@ -50,13 +50,13 @@ public abstract class AbstractCachingConfiguration implements ImportAware {
protected @Nullable AnnotationAttributes enableCaching; protected @Nullable AnnotationAttributes enableCaching;
protected @Nullable Supplier<? extends @Nullable CacheManager> cacheManager; protected @Nullable Supplier<@Nullable CacheManager> cacheManager;
protected @Nullable Supplier<? extends @Nullable CacheResolver> cacheResolver; protected @Nullable Supplier<@Nullable CacheResolver> cacheResolver;
protected @Nullable Supplier<? extends @Nullable KeyGenerator> keyGenerator; protected @Nullable Supplier<@Nullable KeyGenerator> keyGenerator;
protected @Nullable Supplier<? extends @Nullable CacheErrorHandler> errorHandler; protected @Nullable Supplier<@Nullable CacheErrorHandler> errorHandler;
@Override @Override
@ -70,9 +70,8 @@ public abstract class AbstractCachingConfiguration implements ImportAware {
} }
@Autowired @Autowired
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1126
void setConfigurers(ObjectProvider<CachingConfigurer> configurers) { void setConfigurers(ObjectProvider<CachingConfigurer> configurers) {
Supplier<? extends @Nullable CachingConfigurer> configurer = () -> { Supplier<@Nullable CachingConfigurer> configurer = () -> {
List<CachingConfigurer> candidates = configurers.stream().toList(); List<CachingConfigurer> candidates = configurers.stream().toList();
if (CollectionUtils.isEmpty(candidates)) { if (CollectionUtils.isEmpty(candidates)) {
return null; return null;
@ -91,7 +90,7 @@ public abstract class AbstractCachingConfiguration implements ImportAware {
/** /**
* Extract the configuration from the nominated {@link CachingConfigurer}. * 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) { protected void useCachingConfigurer(CachingConfigurerSupplier cachingConfigurerSupplier) {
this.cacheManager = cachingConfigurerSupplier.adapt(CachingConfigurer::cacheManager); this.cacheManager = cachingConfigurerSupplier.adapt(CachingConfigurer::cacheManager);
this.cacheResolver = cachingConfigurerSupplier.adapt(CachingConfigurer::cacheResolver); this.cacheResolver = cachingConfigurerSupplier.adapt(CachingConfigurer::cacheResolver);
@ -104,7 +103,7 @@ public abstract class AbstractCachingConfiguration implements ImportAware {
private final SingletonSupplier<CachingConfigurer> supplier; private final SingletonSupplier<CachingConfigurer> supplier;
public CachingConfigurerSupplier(Supplier<? extends @Nullable CachingConfigurer> supplier) { public CachingConfigurerSupplier(Supplier<@Nullable CachingConfigurer> supplier) {
this.supplier = SingletonSupplier.ofNullable(supplier); this.supplier = SingletonSupplier.ofNullable(supplier);
} }
@ -117,7 +116,7 @@ public abstract class AbstractCachingConfiguration implements ImportAware {
* @param <T> the type of the supplier * @param <T> the type of the supplier
* @return another supplier mapped by the specified function * @return another supplier mapped by the specified function
*/ */
public <T> Supplier<@Nullable T> adapt(Function<CachingConfigurer, ? extends @Nullable T> provider) { public <T> Supplier<@Nullable T> adapt(Function<CachingConfigurer, @Nullable T> provider) {
return () -> { return () -> {
CachingConfigurer cachingConfigurer = this.supplier.get(); CachingConfigurer cachingConfigurer = this.supplier.get();
return (cachingConfigurer != null ? provider.apply(cachingConfigurer) : null); return (cachingConfigurer != null ? provider.apply(cachingConfigurer) : null);

View File

@ -506,7 +506,6 @@ public abstract class AbstractReflectiveMBeanInfoAssembler extends AbstractMBean
* of the {@code MBeanExporter} * of the {@code MBeanExporter}
* @return the {@code MBeanParameterInfo} array * @return the {@code MBeanParameterInfo} array
*/ */
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1127
protected MBeanParameterInfo[] getOperationParameters(Method method, String beanKey) { protected MBeanParameterInfo[] getOperationParameters(Method method, String beanKey) {
ParameterNameDiscoverer paramNameDiscoverer = getParameterNameDiscoverer(); ParameterNameDiscoverer paramNameDiscoverer = getParameterNameDiscoverer();
@Nullable String[] paramNames = (paramNameDiscoverer != null ? paramNameDiscoverer.getParameterNames(method) : null); @Nullable String[] paramNames = (paramNameDiscoverer != null ? paramNameDiscoverer.getParameterNames(method) : null);

View File

@ -67,7 +67,7 @@ public abstract class AbstractAsyncConfiguration implements ImportAware {
* Collect any {@link AsyncConfigurer} beans through autowiring. * Collect any {@link AsyncConfigurer} beans through autowiring.
*/ */
@Autowired @Autowired
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1126 @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1128
void setConfigurers(ObjectProvider<AsyncConfigurer> configurers) { void setConfigurers(ObjectProvider<AsyncConfigurer> configurers) {
SingletonSupplier<AsyncConfigurer> configurer = SingletonSupplier.ofNullable(() -> { SingletonSupplier<AsyncConfigurer> configurer = SingletonSupplier.ofNullable(() -> {
List<AsyncConfigurer> candidates = configurers.stream().toList(); List<AsyncConfigurer> candidates = configurers.stream().toList();

View File

@ -162,7 +162,7 @@ public class SingletonSupplier<T> implements Supplier<@Nullable T> {
* @return the singleton supplier, or {@code null} if the instance supplier was {@code null} * @return the singleton supplier, or {@code null} if the instance supplier was {@code null}
*/ */
@Contract("null -> null; !null -> !null") @Contract("null -> null; !null -> !null")
public static <T> @Nullable SingletonSupplier<T> ofNullable(@Nullable Supplier<? extends @Nullable T> supplier) { public static <T> @Nullable SingletonSupplier<T> ofNullable(@Nullable Supplier<@Nullable T> supplier) {
return (supplier != null ? new SingletonSupplier<>(supplier) : null); return (supplier != null ? new SingletonSupplier<>(supplier) : null);
} }

View File

@ -21,6 +21,7 @@ import java.time.Duration;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.function.Function; import java.util.function.Function;
@ -166,7 +167,7 @@ final class RSocketServiceMethod {
((Mono<?>) responsePublisher).blockOptional()); ((Mono<?>) responsePublisher).blockOptional());
} }
else { else {
return (blockTimeout != null ? return Objects.requireNonNull(blockTimeout != null ?
((Mono<?>) responsePublisher).block(blockTimeout) : ((Mono<?>) responsePublisher).block(blockTimeout) :
((Mono<?>) responsePublisher).block()); ((Mono<?>) responsePublisher).block());
} }

View File

@ -60,7 +60,7 @@ public class SpringSessionContext implements CurrentSessionContext {
public SpringSessionContext(SessionFactoryImplementor sessionFactory) { public SpringSessionContext(SessionFactoryImplementor sessionFactory) {
this.sessionFactory = sessionFactory; this.sessionFactory = sessionFactory;
try { try {
JtaPlatform jtaPlatform = sessionFactory.getServiceRegistry().getService(JtaPlatform.class); JtaPlatform jtaPlatform = sessionFactory.getServiceRegistry().requireService(JtaPlatform.class);
this.transactionManager = jtaPlatform.retrieveTransactionManager(); this.transactionManager = jtaPlatform.retrieveTransactionManager();
if (this.transactionManager != null) { if (this.transactionManager != null) {
this.jtaSessionContext = new SpringJtaSessionContext(sessionFactory); this.jtaSessionContext = new SpringJtaSessionContext(sessionFactory);

View File

@ -20,6 +20,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import kotlin.Unit; import kotlin.Unit;
import kotlin.jvm.JvmClassMappingKt; import kotlin.jvm.JvmClassMappingKt;
@ -317,7 +318,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
KType type = parameter.getType(); KType type = parameter.getType();
if (!(type.isMarkedNullable() && arg == null) && type.getClassifier() instanceof KClass<?> kClass if (!(type.isMarkedNullable() && arg == null) && type.getClassifier() instanceof KClass<?> kClass
&& KotlinDetector.isInlineClass(JvmClassMappingKt.getJavaClass(kClass))) { && KotlinDetector.isInlineClass(JvmClassMappingKt.getJavaClass(kClass))) {
KFunction<?> constructor = KClasses.getPrimaryConstructor(kClass); KFunction<?> constructor = Objects.requireNonNull(KClasses.getPrimaryConstructor(kClass));
if (!KCallablesJvm.isAccessible(constructor)) { if (!KCallablesJvm.isAccessible(constructor)) {
KCallablesJvm.setAccessible(constructor, true); KCallablesJvm.setAccessible(constructor, true);
} }

View File

@ -94,6 +94,7 @@ public abstract class AbstractReactorHttpExchangeAdapter implements ReactorHttpE
} }
@Override @Override
@Nullable
public <T> T exchangeForBody(HttpRequestValues requestValues, ParameterizedTypeReference<T> bodyType) { public <T> T exchangeForBody(HttpRequestValues requestValues, ParameterizedTypeReference<T> bodyType) {
return (this.blockTimeout != null ? return (this.blockTimeout != null ?
exchangeForBodyMono(requestValues, bodyType).block(this.blockTimeout) : exchangeForBodyMono(requestValues, bodyType).block(this.blockTimeout) :

View File

@ -140,7 +140,6 @@ public class DefaultUriBuilderFactory implements UriBuilderFactory {
* with a Map of variables. * with a Map of variables.
* @param defaultUriVariables default URI variable values * @param defaultUriVariables default URI variable values
*/ */
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1126
public void setDefaultUriVariables(@Nullable Map<String, ? extends @Nullable Object> defaultUriVariables) { public void setDefaultUriVariables(@Nullable Map<String, ? extends @Nullable Object> defaultUriVariables) {
if (defaultUriVariables != null) { if (defaultUriVariables != null) {
if (this.defaultUriVariables == null) { if (this.defaultUriVariables == null) {
@ -432,7 +431,6 @@ public class DefaultUriBuilderFactory implements UriBuilderFactory {
} }
@Override @Override
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1126
public URI build(Map<String, ?> uriVars) { public URI build(Map<String, ?> uriVars) {
if (!CollectionUtils.isEmpty(defaultUriVariables)) { if (!CollectionUtils.isEmpty(defaultUriVariables)) {
Map<String, Object> map = new HashMap<>(defaultUriVariables.size() + uriVars.size()); Map<String, Object> map = new HashMap<>(defaultUriVariables.size() + uriVars.size());
@ -448,7 +446,6 @@ public class DefaultUriBuilderFactory implements UriBuilderFactory {
} }
@Override @Override
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1126
public URI build(@Nullable Object... uriVars) { public URI build(@Nullable Object... uriVars) {
if (ObjectUtils.isEmpty(uriVars) && !CollectionUtils.isEmpty(defaultUriVariables)) { if (ObjectUtils.isEmpty(uriVars) && !CollectionUtils.isEmpty(defaultUriVariables)) {
return build(Collections.emptyMap()); return build(Collections.emptyMap());

View File

@ -232,8 +232,7 @@ class DefaultClientResponse implements ClientResponse {
}); });
} }
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1126 private Function<ResolvableType, @Nullable Object> initDecodeFunction(byte[] body, @Nullable MediaType contentType) {
private Function<ResolvableType, ? extends @Nullable Object> initDecodeFunction(byte[] body, @Nullable MediaType contentType) {
return targetType -> { return targetType -> {
if (ObjectUtils.isEmpty(body)) { if (ObjectUtils.isEmpty(body)) {
return null; return null;

View File

@ -92,7 +92,6 @@ public class CompositeRequestCondition extends AbstractRequestCondition<Composit
} }
@Override @Override
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1126
protected Collection<? extends @Nullable Object> getContent() { protected Collection<? extends @Nullable Object> getContent() {
return (!isEmpty() ? getConditions() : Collections.emptyList()); return (!isEmpty() ? getConditions() : Collections.emptyList());
} }

View File

@ -23,6 +23,7 @@ import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.stream.Stream; import java.util.stream.Stream;
import kotlin.Unit; import kotlin.Unit;
@ -355,7 +356,7 @@ public class InvocableHandlerMethod extends HandlerMethod {
KType type = parameter.getType(); KType type = parameter.getType();
if (!(type.isMarkedNullable() && arg == null) && type.getClassifier() instanceof KClass<?> kClass if (!(type.isMarkedNullable() && arg == null) && type.getClassifier() instanceof KClass<?> kClass
&& KotlinDetector.isInlineClass(JvmClassMappingKt.getJavaClass(kClass))) { && KotlinDetector.isInlineClass(JvmClassMappingKt.getJavaClass(kClass))) {
KFunction<?> constructor = KClasses.getPrimaryConstructor(kClass); KFunction<?> constructor = Objects.requireNonNull(KClasses.getPrimaryConstructor(kClass));
if (!KCallablesJvm.isAccessible(constructor)) { if (!KCallablesJvm.isAccessible(constructor)) {
KCallablesJvm.setAccessible(constructor, true); KCallablesJvm.setAccessible(constructor, true);
} }

View File

@ -16,6 +16,8 @@
package org.springframework.web.reactive.result.method.annotation; package org.springframework.web.reactive.result.method.annotation;
import java.util.Objects;
import org.jspecify.annotations.Nullable; import org.jspecify.annotations.Nullable;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
@ -69,7 +71,7 @@ public abstract class AbstractNamedValueSyncArgumentResolver extends AbstractNam
MethodParameter parameter, BindingContext context, ServerWebExchange exchange) { MethodParameter parameter, BindingContext context, ServerWebExchange exchange) {
// This won't block since resolveName below doesn't // This won't block since resolveName below doesn't
return resolveArgument(parameter, context, exchange).block(); return Objects.requireNonNull(resolveArgument(parameter, context, exchange).block());
} }
@Override @Override