Specify generic type nullness in spring-context

Also in spring-context-support.

See gh-34140
This commit is contained in:
Sébastien Deleuze
2025-01-13 20:50:56 +01:00
parent 928a3c7184
commit 435cb0c7d6
30 changed files with 112 additions and 103 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 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.
@@ -16,6 +16,7 @@
package org.springframework.cache.jcache;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.function.Function;
@@ -134,7 +135,8 @@ public class JCacheCache extends AbstractValueAdaptingCache {
private static final PutIfAbsentEntryProcessor INSTANCE = new PutIfAbsentEntryProcessor();
@Override
public @Nullable Object process(MutableEntry<Object, Object> entry, Object... arguments) throws EntryProcessorException {
@SuppressWarnings("NullAway") // Overridden method does not define nullness
public @Nullable Object process(MutableEntry<Object, @Nullable Object> entry, @Nullable Object... arguments) throws EntryProcessorException {
Object existingValue = entry.getValue();
if (existingValue == null) {
entry.setValue(arguments[0]);
@@ -146,11 +148,11 @@ public class JCacheCache extends AbstractValueAdaptingCache {
private static final class ValueLoaderEntryProcessor implements EntryProcessor<Object, Object, Object> {
private final Function<Object, Object> fromStoreValue;
private final Function<Object, @Nullable Object> fromStoreValue;
private final Function<Object, Object> toStoreValue;
private ValueLoaderEntryProcessor(Function<Object, Object> fromStoreValue,
private ValueLoaderEntryProcessor(Function<Object, @Nullable Object> fromStoreValue,
Function<Object, Object> toStoreValue) {
this.fromStoreValue = fromStoreValue;
@@ -158,16 +160,16 @@ public class JCacheCache extends AbstractValueAdaptingCache {
}
@Override
@SuppressWarnings("unchecked")
public @Nullable Object process(MutableEntry<Object, Object> entry, Object... arguments) throws EntryProcessorException {
@SuppressWarnings({"unchecked","NullAway"}) // Overridden method does not define nullness
public @Nullable Object process(MutableEntry<Object, @Nullable Object> entry, @Nullable Object... arguments) throws EntryProcessorException {
Callable<Object> valueLoader = (Callable<Object>) arguments[0];
if (entry.exists()) {
return this.fromStoreValue.apply(entry.getValue());
return this.fromStoreValue.apply(Objects.requireNonNull(entry.getValue()));
}
else {
Object value;
try {
value = valueLoader.call();
value = Objects.requireNonNull(valueLoader).call();
}
catch (Exception ex) {
throw new EntryProcessorException("Value loader '" + valueLoader + "' failed " +

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 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.
@@ -41,10 +41,11 @@ import org.springframework.context.annotation.Role;
@Configuration(proxyBeanMethods = false)
public abstract class AbstractJCacheConfiguration extends AbstractCachingConfiguration {
protected @Nullable Supplier<CacheResolver> exceptionCacheResolver;
protected @Nullable Supplier<? extends @Nullable CacheResolver> exceptionCacheResolver;
@Override
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1126
protected void useCachingConfigurer(CachingConfigurerSupplier cachingConfigurerSupplier) {
super.useCachingConfigurer(cachingConfigurerSupplier);
this.exceptionCacheResolver = cachingConfigurerSupplier.adapt(config -> {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -79,8 +79,8 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc
* @since 5.1
*/
public DefaultJCacheOperationSource(
@Nullable Supplier<CacheManager> cacheManager, @Nullable Supplier<CacheResolver> cacheResolver,
@Nullable Supplier<CacheResolver> exceptionCacheResolver, @Nullable Supplier<KeyGenerator> keyGenerator) {
@Nullable Supplier<? extends @Nullable CacheManager> cacheManager, @Nullable Supplier<? extends @Nullable CacheResolver> cacheResolver,
@Nullable Supplier<? extends @Nullable CacheResolver> exceptionCacheResolver, @Nullable Supplier<? extends @Nullable KeyGenerator> keyGenerator) {
this.cacheManager = SingletonSupplier.ofNullable(cacheManager);
this.cacheResolver = SingletonSupplier.ofNullable(cacheResolver);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2025 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.
@@ -96,7 +96,7 @@ public class JCacheAspectSupport extends AbstractCacheInvoker implements Initial
}
protected @Nullable Object execute(CacheOperationInvoker invoker, Object target, Method method, Object[] args) {
protected @Nullable Object execute(CacheOperationInvoker invoker, Object target, Method method, @Nullable Object[] args) {
// Check whether aspect is enabled to cope with cases where the AJ is pulled in automatically
if (this.initialized) {
Class<?> targetClass = AopProxyUtils.ultimateTargetClass(target);
@@ -113,7 +113,7 @@ public class JCacheAspectSupport extends AbstractCacheInvoker implements Initial
@SuppressWarnings("unchecked")
private CacheOperationInvocationContext<?> createCacheOperationInvocationContext(
Object target, Object[] args, JCacheOperation<?> operation) {
Object target, @Nullable Object[] args, JCacheOperation<?> operation) {
return new DefaultCacheInvocationContext<>(
(JCacheOperation<Annotation>) operation, target, args);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2025 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.
@@ -60,7 +60,7 @@ public class JCacheInterceptor extends JCacheAspectSupport implements MethodInte
* applying the default error handler if the supplier is not resolvable
* @since 5.1
*/
public JCacheInterceptor(@Nullable Supplier<CacheErrorHandler> errorHandler) {
public JCacheInterceptor(@Nullable Supplier<? extends @Nullable CacheErrorHandler> errorHandler) {
this.errorHandler = new SingletonSupplier<>(errorHandler, SimpleCacheErrorHandler::new);
}