Browse Source

Upgrade NullAway to 0.12.4

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

Closes gh-34525
pull/34532/head
Sébastien Deleuze 10 months ago
parent
commit
7bc712e304
  1. 2
      gradle/spring-module.gradle
  2. 4
      spring-context-support/src/main/java/org/springframework/cache/jcache/config/AbstractJCacheConfiguration.java
  3. 4
      spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultJCacheOperationSource.java
  4. 17
      spring-context/src/main/java/org/springframework/cache/annotation/AbstractCachingConfiguration.java
  5. 1
      spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractReflectiveMBeanInfoAssembler.java
  6. 2
      spring-context/src/main/java/org/springframework/scheduling/annotation/AbstractAsyncConfiguration.java
  7. 2
      spring-core/src/main/java/org/springframework/util/function/SingletonSupplier.java
  8. 3
      spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceMethod.java
  9. 2
      spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringSessionContext.java
  10. 3
      spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java
  11. 1
      spring-web/src/main/java/org/springframework/web/service/invoker/AbstractReactorHttpExchangeAdapter.java
  12. 3
      spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java
  13. 3
      spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponse.java
  14. 1
      spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/CompositeRequestCondition.java
  15. 3
      spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java
  16. 4
      spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractNamedValueSyncArgumentResolver.java

2
gradle/spring-module.gradle

@ -13,7 +13,7 @@ dependencies { @@ -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'
}

4
spring-context-support/src/main/java/org/springframework/cache/jcache/config/AbstractJCacheConfiguration.java vendored

@ -41,11 +41,11 @@ import org.springframework.context.annotation.Role; @@ -41,11 +41,11 @@ import org.springframework.context.annotation.Role;
@Configuration(proxyBeanMethods = false)
public abstract class AbstractJCacheConfiguration extends AbstractCachingConfiguration {
protected @Nullable Supplier<? extends @Nullable CacheResolver> 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 -> {

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

@ -79,8 +79,8 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc @@ -79,8 +79,8 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc
* @since 5.1
*/
public DefaultJCacheOperationSource(
@Nullable Supplier<? extends @Nullable CacheManager> cacheManager, @Nullable Supplier<? extends @Nullable CacheResolver> cacheResolver,
@Nullable Supplier<? extends @Nullable CacheResolver> exceptionCacheResolver, @Nullable Supplier<? extends @Nullable KeyGenerator> 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);

17
spring-context/src/main/java/org/springframework/cache/annotation/AbstractCachingConfiguration.java vendored

@ -50,13 +50,13 @@ public abstract class AbstractCachingConfiguration implements ImportAware { @@ -50,13 +50,13 @@ public abstract class AbstractCachingConfiguration implements ImportAware {
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
@ -70,9 +70,8 @@ public abstract class AbstractCachingConfiguration implements ImportAware { @@ -70,9 +70,8 @@ public abstract class AbstractCachingConfiguration implements ImportAware {
}
@Autowired
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1126
void setConfigurers(ObjectProvider<CachingConfigurer> configurers) {
Supplier<? extends @Nullable CachingConfigurer> configurer = () -> {
Supplier<@Nullable CachingConfigurer> configurer = () -> {
List<CachingConfigurer> candidates = configurers.stream().toList();
if (CollectionUtils.isEmpty(candidates)) {
return null;
@ -91,7 +90,7 @@ public abstract class AbstractCachingConfiguration implements ImportAware { @@ -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 { @@ -104,7 +103,7 @@ public abstract class AbstractCachingConfiguration implements ImportAware {
private final SingletonSupplier<CachingConfigurer> supplier;
public CachingConfigurerSupplier(Supplier<? extends @Nullable CachingConfigurer> supplier) {
public CachingConfigurerSupplier(Supplier<@Nullable CachingConfigurer> supplier) {
this.supplier = SingletonSupplier.ofNullable(supplier);
}
@ -117,7 +116,7 @@ public abstract class AbstractCachingConfiguration implements ImportAware { @@ -117,7 +116,7 @@ public abstract class AbstractCachingConfiguration implements ImportAware {
* @param <T> the type of the supplier
* @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 () -> {
CachingConfigurer cachingConfigurer = this.supplier.get();
return (cachingConfigurer != null ? provider.apply(cachingConfigurer) : null);

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

@ -506,7 +506,6 @@ public abstract class AbstractReflectiveMBeanInfoAssembler extends AbstractMBean @@ -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);

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

@ -67,7 +67,7 @@ public abstract class AbstractAsyncConfiguration implements ImportAware { @@ -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<AsyncConfigurer> configurers) {
SingletonSupplier<AsyncConfigurer> configurer = SingletonSupplier.ofNullable(() -> {
List<AsyncConfigurer> candidates = configurers.stream().toList();

2
spring-core/src/main/java/org/springframework/util/function/SingletonSupplier.java

@ -162,7 +162,7 @@ public class SingletonSupplier<T> implements Supplier<@Nullable T> { @@ -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}
*/
@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);
}

3
spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceMethod.java

@ -21,6 +21,7 @@ import java.time.Duration; @@ -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 { @@ -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());
}

2
spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringSessionContext.java

@ -60,7 +60,7 @@ public class SpringSessionContext implements CurrentSessionContext { @@ -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);

3
spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java

@ -20,6 +20,7 @@ import java.lang.reflect.InvocationTargetException; @@ -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 { @@ -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);
}

1
spring-web/src/main/java/org/springframework/web/service/invoker/AbstractReactorHttpExchangeAdapter.java

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

3
spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java

@ -140,7 +140,6 @@ public class DefaultUriBuilderFactory implements UriBuilderFactory { @@ -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<String, ? extends @Nullable Object> defaultUriVariables) {
if (defaultUriVariables != null) {
if (this.defaultUriVariables == null) {
@ -432,7 +431,6 @@ public class DefaultUriBuilderFactory implements UriBuilderFactory { @@ -432,7 +431,6 @@ public class DefaultUriBuilderFactory implements UriBuilderFactory {
}
@Override
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1126
public URI build(Map<String, ?> uriVars) {
if (!CollectionUtils.isEmpty(defaultUriVariables)) {
Map<String, Object> map = new HashMap<>(defaultUriVariables.size() + uriVars.size());
@ -448,7 +446,6 @@ public class DefaultUriBuilderFactory implements UriBuilderFactory { @@ -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());

3
spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponse.java

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

1
spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/CompositeRequestCondition.java

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

3
spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java

@ -23,6 +23,7 @@ import java.lang.reflect.Type; @@ -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 { @@ -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);
}

4
spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractNamedValueSyncArgumentResolver.java

@ -16,6 +16,8 @@ @@ -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 @@ -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

Loading…
Cancel
Save