Skip to content

Commit

Permalink
Upgrade NullAway to 0.12.4
Browse files Browse the repository at this point in the history
This commit also slightly refines nullness but without
significant user-side impact expected.

Closes gh-34525
  • Loading branch information
sdeleuze committed Mar 3, 2025
1 parent f7db4bf commit 7bc712e
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 28 deletions.
2 changes: 1 addition & 1 deletion gradle/spring-module.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
@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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public DefaultJCacheOperationSource() {
* @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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -70,9 +70,8 @@ public void setImportMetadata(AnnotationMetadata importMetadata) {
}

@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;
Expand All @@ -91,7 +90,7 @@ void setConfigurers(ObjectProvider<CachingConfigurer> configurers) {
/**
* 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);
Expand All @@ -104,7 +103,7 @@ protected static class CachingConfigurerSupplier {

private final SingletonSupplier<CachingConfigurer> supplier;

public CachingConfigurerSupplier(Supplier<? extends @Nullable CachingConfigurer> supplier) {
public CachingConfigurerSupplier(Supplier<@Nullable CachingConfigurer> supplier) {
this.supplier = SingletonSupplier.ofNullable(supplier);
}

Expand All @@ -117,7 +116,7 @@ public CachingConfigurerSupplier(Supplier<? extends @Nullable CachingConfigurer>
* @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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ protected String getOperationDescription(Method method, String beanKey) {
* 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void setImportMetadata(AnnotationMetadata importMetadata) {
* 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public static <T> SingletonSupplier<T> of(Supplier<T> supplier) {
* @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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;

Expand Down Expand Up @@ -166,7 +167,7 @@ else if (reactiveAdapter == null) {
((Mono<?>) responsePublisher).blockOptional());
}
else {
return (blockTimeout != null ?
return Objects.requireNonNull(blockTimeout != null ?
((Mono<?>) responsePublisher).block(blockTimeout) :
((Mono<?>) responsePublisher).block());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Map;
import java.util.Objects;

import kotlin.Unit;
import kotlin.jvm.JvmClassMappingKt;
Expand Down Expand Up @@ -317,7 +318,7 @@ private static class KotlinDelegate {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public HttpHeaders exchangeForHeaders(HttpRequestValues requestValues) {
}

@Override
@Nullable
public <T> T exchangeForBody(HttpRequestValues requestValues, ParameterizedTypeReference<T> bodyType) {
return (this.blockTimeout != null ?
exchangeForBodyMono(requestValues, bodyType).block(this.blockTimeout) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ public EncodingMode getEncodingMode() {
* 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) {
Expand Down Expand Up @@ -432,7 +431,6 @@ public DefaultUriBuilder fragment(@Nullable String fragment) {
}

@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());
Expand All @@ -448,7 +446,6 @@ public URI build(Map<String, ?> uriVars) {
}

@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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ public Mono<WebClientResponseException> createException() {
});
}

@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public boolean isEmpty() {
}

@Override
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1126
protected Collection<? extends @Nullable Object> getContent() {
return (!isEmpty() ? getConditions() : Collections.emptyList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Stream;

import kotlin.Unit;
Expand Down Expand Up @@ -355,7 +356,7 @@ private static class KotlinDelegate {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -69,7 +71,7 @@ public Object resolveArgumentValue(
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
Expand Down

0 comments on commit 7bc712e

Please sign in to comment.