Switch to JSpecify annotations

This commit updates the whole Spring Framework codebase to use JSpecify
annotations instead of Spring null-safety annotations with JSR 305
semantics.

JSpecify provides signficant enhancements such as properly defined
specifications, a canonical dependency with no split-package issue,
better tooling, better Kotlin integration and the capability to specify
generic type, array and varargs element null-safety. Generic type
null-safety is not defined by this commit yet and will be specified
later.

A key difference is that Spring null-safety annotations, following
JSR 305 semantics, apply to fields, parameters and return values,
while JSpecify annotations apply to type usages. That's why this
commit moves nullability annotations closer to the type for fields
and return values.

See gh-28797
This commit is contained in:
Sébastien Deleuze
2024-12-03 15:22:37 +01:00
parent fcb8aed03f
commit bc5d771a06
3459 changed files with 14118 additions and 22059 deletions

View File

@@ -20,7 +20,7 @@ import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Interface that defines common cache operations.
@@ -65,8 +65,7 @@ public interface Cache {
* @see #get(Object, Class)
* @see #get(Object, Callable)
*/
@Nullable
ValueWrapper get(Object key);
@Nullable ValueWrapper get(Object key);
/**
* Return the value to which this cache maps the specified key,
@@ -86,8 +85,7 @@ public interface Cache {
* @since 4.0
* @see #get(Object)
*/
@Nullable
<T> T get(Object key, @Nullable Class<T> type);
<T> @Nullable T get(Object key, @Nullable Class<T> type);
/**
* Return the value to which this cache maps the specified key, obtaining
@@ -105,8 +103,7 @@ public interface Cache {
* @since 4.3
* @see #get(Object)
*/
@Nullable
<T> T get(Object key, Callable<T> valueLoader);
<T> @Nullable T get(Object key, Callable<T> valueLoader);
/**
* Return the value to which this cache maps the specified key,
@@ -136,8 +133,7 @@ public interface Cache {
* @since 6.1
* @see #retrieve(Object, Supplier)
*/
@Nullable
default CompletableFuture<?> retrieve(Object key) {
default @Nullable CompletableFuture<?> retrieve(Object key) {
throw new UnsupportedOperationException(
getClass().getName() + " does not support CompletableFuture-based retrieval");
}
@@ -214,8 +210,7 @@ public interface Cache {
* @since 4.1
* @see #put(Object, Object)
*/
@Nullable
default ValueWrapper putIfAbsent(Object key, @Nullable Object value) {
default @Nullable ValueWrapper putIfAbsent(Object key, @Nullable Object value) {
ValueWrapper existingValue = get(key);
if (existingValue == null) {
put(key, value);
@@ -299,8 +294,7 @@ public interface Cache {
/**
* Return the actual value in the cache.
*/
@Nullable
Object get();
@Nullable Object get();
}
@@ -312,16 +306,14 @@ public interface Cache {
@SuppressWarnings("serial")
class ValueRetrievalException extends RuntimeException {
@Nullable
private final Object key;
private final @Nullable Object key;
public ValueRetrievalException(@Nullable Object key, Callable<?> loader, @Nullable Throwable ex) {
super(String.format("Value for key '%s' could not be loaded using '%s'", key, loader), ex);
this.key = key;
}
@Nullable
public Object getKey() {
public @Nullable Object getKey() {
return this.key;
}
}

View File

@@ -18,7 +18,7 @@ package org.springframework.cache;
import java.util.Collection;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Spring's central cache manager SPI.
@@ -39,8 +39,7 @@ public interface CacheManager {
* @return the associated cache, or {@code null} if such a cache
* does not exist or could be not created
*/
@Nullable
Cache getCache(String name);
@Nullable Cache getCache(String name);
/**
* Get a collection of the cache names known by this manager.

View File

@@ -20,6 +20,8 @@ import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
@@ -30,7 +32,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportAware;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.function.SingletonSupplier;
@@ -47,20 +48,15 @@ import org.springframework.util.function.SingletonSupplier;
@Configuration(proxyBeanMethods = false)
public abstract class AbstractCachingConfiguration implements ImportAware {
@Nullable
protected AnnotationAttributes enableCaching;
protected @Nullable AnnotationAttributes enableCaching;
@Nullable
protected Supplier<CacheManager> cacheManager;
protected @Nullable Supplier<CacheManager> cacheManager;
@Nullable
protected Supplier<CacheResolver> cacheResolver;
protected @Nullable Supplier<CacheResolver> cacheResolver;
@Nullable
protected Supplier<KeyGenerator> keyGenerator;
protected @Nullable Supplier<KeyGenerator> keyGenerator;
@Nullable
protected Supplier<CacheErrorHandler> errorHandler;
protected @Nullable Supplier<CacheErrorHandler> errorHandler;
@Override
@@ -119,8 +115,7 @@ public abstract class AbstractCachingConfiguration implements ImportAware {
* @param <T> the type of the supplier
* @return another supplier mapped by the specified function
*/
@Nullable
public <T> Supplier<T> adapt(Function<CachingConfigurer, T> provider) {
public <T> @Nullable Supplier<T> adapt(Function<CachingConfigurer, T> provider) {
return () -> {
CachingConfigurer cachingConfigurer = this.supplier.get();
return (cachingConfigurer != null ? provider.apply(cachingConfigurer) : null);

View File

@@ -23,9 +23,10 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.cache.interceptor.AbstractFallbackCacheOperationSource;
import org.springframework.cache.interceptor.CacheOperation;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -120,14 +121,12 @@ public class AnnotationCacheOperationSource extends AbstractFallbackCacheOperati
}
@Override
@Nullable
protected Collection<CacheOperation> findCacheOperations(Class<?> clazz) {
protected @Nullable Collection<CacheOperation> findCacheOperations(Class<?> clazz) {
return determineCacheOperations(parser -> parser.parseCacheAnnotations(clazz));
}
@Override
@Nullable
protected Collection<CacheOperation> findCacheOperations(Method method) {
protected @Nullable Collection<CacheOperation> findCacheOperations(Method method) {
return determineCacheOperations(parser -> parser.parseCacheAnnotations(method));
}
@@ -140,8 +139,7 @@ public class AnnotationCacheOperationSource extends AbstractFallbackCacheOperati
* @param provider the cache operation provider to use
* @return the configured caching operations, or {@code null} if none found
*/
@Nullable
protected Collection<CacheOperation> determineCacheOperations(CacheOperationProvider provider) {
protected @Nullable Collection<CacheOperation> determineCacheOperations(CacheOperationProvider provider) {
Collection<CacheOperation> ops = null;
for (CacheAnnotationParser parser : this.annotationParsers) {
Collection<CacheOperation> annOps = provider.getCacheOperations(parser);
@@ -195,8 +193,7 @@ public class AnnotationCacheOperationSource extends AbstractFallbackCacheOperati
* @param parser the parser to use
* @return the cache operations, or {@code null} if none found
*/
@Nullable
Collection<CacheOperation> getCacheOperations(CacheAnnotationParser parser);
@Nullable Collection<CacheOperation> getCacheOperations(CacheAnnotationParser parser);
}
}

View File

@@ -19,8 +19,9 @@ package org.springframework.cache.annotation;
import java.lang.reflect.Method;
import java.util.Collection;
import org.jspecify.annotations.Nullable;
import org.springframework.cache.interceptor.CacheOperation;
import org.springframework.lang.Nullable;
/**
* Strategy interface for parsing known caching annotation types.
@@ -64,8 +65,7 @@ public interface CacheAnnotationParser {
* @return the configured caching operation, or {@code null} if none found
* @see AnnotationCacheOperationSource#findCacheOperations(Class)
*/
@Nullable
Collection<CacheOperation> parseCacheAnnotations(Class<?> type);
@Nullable Collection<CacheOperation> parseCacheAnnotations(Class<?> type);
/**
* Parse the cache definition for the given method,
@@ -76,7 +76,6 @@ public interface CacheAnnotationParser {
* @return the configured caching operation, or {@code null} if none found
* @see AnnotationCacheOperationSource#findCacheOperations(Method)
*/
@Nullable
Collection<CacheOperation> parseCacheAnnotations(Method method);
@Nullable Collection<CacheOperation> parseCacheAnnotations(Method method);
}

View File

@@ -16,11 +16,12 @@
package org.springframework.cache.annotation;
import org.jspecify.annotations.Nullable;
import org.springframework.cache.CacheManager;
import org.springframework.cache.interceptor.CacheErrorHandler;
import org.springframework.cache.interceptor.CacheResolver;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.lang.Nullable;
/**
* Interface to be implemented by @{@link org.springframework.context.annotation.Configuration
@@ -66,8 +67,7 @@ public interface CachingConfigurer {
* </pre>
* See @{@link EnableCaching} for more complete examples.
*/
@Nullable
default CacheManager cacheManager() {
default @Nullable CacheManager cacheManager() {
return null;
}
@@ -94,8 +94,7 @@ public interface CachingConfigurer {
* </pre>
* See {@link EnableCaching} for more complete examples.
*/
@Nullable
default CacheResolver cacheResolver() {
default @Nullable CacheResolver cacheResolver() {
return null;
}
@@ -105,8 +104,7 @@ public interface CachingConfigurer {
* is used.
* See @{@link EnableCaching} for more complete examples.
*/
@Nullable
default KeyGenerator keyGenerator() {
default @Nullable KeyGenerator keyGenerator() {
return null;
}
@@ -116,8 +114,7 @@ public interface CachingConfigurer {
* is used, which throws the exception back at the client.
* See @{@link EnableCaching} for more complete examples.
*/
@Nullable
default CacheErrorHandler errorHandler() {
default @Nullable CacheErrorHandler errorHandler() {
return null;
}

View File

@@ -16,11 +16,12 @@
package org.springframework.cache.annotation;
import org.jspecify.annotations.Nullable;
import org.springframework.cache.CacheManager;
import org.springframework.cache.interceptor.CacheErrorHandler;
import org.springframework.cache.interceptor.CacheResolver;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.lang.Nullable;
/**
* An implementation of {@link CachingConfigurer} with empty methods allowing
@@ -35,26 +36,22 @@ import org.springframework.lang.Nullable;
public class CachingConfigurerSupport implements CachingConfigurer {
@Override
@Nullable
public CacheManager cacheManager() {
public @Nullable CacheManager cacheManager() {
return null;
}
@Override
@Nullable
public CacheResolver cacheResolver() {
public @Nullable CacheResolver cacheResolver() {
return null;
}
@Override
@Nullable
public KeyGenerator keyGenerator() {
public @Nullable KeyGenerator keyGenerator() {
return null;
}
@Override
@Nullable
public CacheErrorHandler errorHandler() {
public @Nullable CacheErrorHandler errorHandler() {
return null;
}

View File

@@ -24,13 +24,14 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.cache.interceptor.CacheEvictOperation;
import org.springframework.cache.interceptor.CacheOperation;
import org.springframework.cache.interceptor.CachePutOperation;
import org.springframework.cache.interceptor.CacheableOperation;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
@@ -58,21 +59,18 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
}
@Override
@Nullable
public Collection<CacheOperation> parseCacheAnnotations(Class<?> type) {
public @Nullable Collection<CacheOperation> parseCacheAnnotations(Class<?> type) {
DefaultCacheConfig defaultConfig = new DefaultCacheConfig(type);
return parseCacheAnnotations(defaultConfig, type);
}
@Override
@Nullable
public Collection<CacheOperation> parseCacheAnnotations(Method method) {
public @Nullable Collection<CacheOperation> parseCacheAnnotations(Method method) {
DefaultCacheConfig defaultConfig = new DefaultCacheConfig(method.getDeclaringClass());
return parseCacheAnnotations(defaultConfig, method);
}
@Nullable
private Collection<CacheOperation> parseCacheAnnotations(DefaultCacheConfig cachingConfig, AnnotatedElement ae) {
private @Nullable Collection<CacheOperation> parseCacheAnnotations(DefaultCacheConfig cachingConfig, AnnotatedElement ae) {
Collection<CacheOperation> ops = parseCacheAnnotations(cachingConfig, ae, false);
if (ops != null && ops.size() > 1) {
// More than one operation found -> local declarations override interface-declared ones...
@@ -84,8 +82,7 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
return ops;
}
@Nullable
private Collection<CacheOperation> parseCacheAnnotations(
private @Nullable Collection<CacheOperation> parseCacheAnnotations(
DefaultCacheConfig cachingConfig, AnnotatedElement ae, boolean localOnly) {
Collection<? extends Annotation> annotations = (localOnly ?
@@ -232,17 +229,13 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
private final Class<?> target;
@Nullable
private String[] cacheNames;
private String @Nullable [] cacheNames;
@Nullable
private String keyGenerator;
private @Nullable String keyGenerator;
@Nullable
private String cacheManager;
private @Nullable String cacheManager;
@Nullable
private String cacheResolver;
private @Nullable String cacheResolver;
private boolean initialized = false;

View File

@@ -3,9 +3,7 @@
* Hooked into Spring's cache interception infrastructure via
* {@link org.springframework.cache.interceptor.CacheOperationSource}.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.cache.annotation;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -23,9 +23,10 @@ import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ForkJoinPool;
import java.util.function.Supplier;
import org.jspecify.annotations.Nullable;
import org.springframework.cache.support.AbstractValueAdaptingCache;
import org.springframework.core.serializer.support.SerializationDelegate;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -57,8 +58,7 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache {
private final ConcurrentMap<Object, Object> store;
@Nullable
private final SerializationDelegate serialization;
private final @Nullable SerializationDelegate serialization;
/**
@@ -137,15 +137,13 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache {
}
@Override
@Nullable
protected Object lookup(Object key) {
protected @Nullable Object lookup(Object key) {
return this.store.get(key);
}
@SuppressWarnings("unchecked")
@Override
@Nullable
public <T> T get(Object key, Callable<T> valueLoader) {
public <T> @Nullable T get(Object key, Callable<T> valueLoader) {
return (T) fromStoreValue(this.store.computeIfAbsent(key, k -> {
try {
return toStoreValue(valueLoader.call());
@@ -157,8 +155,7 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache {
}
@Override
@Nullable
public CompletableFuture<?> retrieve(Object key) {
public @Nullable CompletableFuture<?> retrieve(Object key) {
Object value = lookup(key);
return (value != null ? CompletableFuture.completedFuture(
isAllowNullValues() ? toValueWrapper(value) : fromStoreValue(value)) : null);
@@ -177,8 +174,7 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache {
}
@Override
@Nullable
public ValueWrapper putIfAbsent(Object key, @Nullable Object value) {
public @Nullable ValueWrapper putIfAbsent(Object key, @Nullable Object value) {
Object existing = this.store.putIfAbsent(key, toStoreValue(value));
return toValueWrapper(existing);
}
@@ -223,8 +219,7 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache {
}
@Override
@Nullable
protected Object fromStoreValue(@Nullable Object storeValue) {
protected @Nullable Object fromStoreValue(@Nullable Object storeValue) {
if (storeValue != null && this.serialization != null) {
try {
return super.fromStoreValue(this.serialization.deserializeFromByteArray((byte[]) storeValue));

View File

@@ -18,10 +18,11 @@ package org.springframework.cache.concurrent;
import java.util.concurrent.ConcurrentMap;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
@@ -42,13 +43,11 @@ public class ConcurrentMapCacheFactoryBean
private String name = "";
@Nullable
private ConcurrentMap<Object, Object> store;
private @Nullable ConcurrentMap<Object, Object> store;
private boolean allowNullValues = true;
@Nullable
private ConcurrentMapCache cache;
private @Nullable ConcurrentMapCache cache;
/**
@@ -92,8 +91,7 @@ public class ConcurrentMapCacheFactoryBean
@Override
@Nullable
public ConcurrentMapCache getObject() {
public @Nullable ConcurrentMapCache getObject() {
return this.cache;
}

View File

@@ -24,11 +24,12 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Supplier;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.core.serializer.support.SerializationDelegate;
import org.springframework.lang.Nullable;
/**
* {@link CacheManager} implementation that lazily builds {@link ConcurrentMapCache}
@@ -60,8 +61,7 @@ public class ConcurrentMapCacheManager implements CacheManager, BeanClassLoaderA
private boolean storeByValue = false;
@Nullable
private SerializationDelegate serialization;
private @Nullable SerializationDelegate serialization;
/**
@@ -166,8 +166,7 @@ public class ConcurrentMapCacheManager implements CacheManager, BeanClassLoaderA
}
@Override
@Nullable
public Cache getCache(String name) {
public @Nullable Cache getCache(String name) {
Cache cache = this.cacheMap.get(name);
if (cache == null && this.dynamic) {
cache = this.cacheMap.computeIfAbsent(name, this::createConcurrentMapCache);

View File

@@ -4,9 +4,7 @@
* and {@link org.springframework.cache.Cache Cache} implementation for
* use in a Spring context, using a JDK based thread pool at runtime.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.cache.concurrent;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -16,6 +16,7 @@
package org.springframework.cache.config;
import org.jspecify.annotations.Nullable;
import org.w3c.dom.Element;
import org.springframework.aop.config.AopNamespaceUtils;
@@ -28,7 +29,6 @@ import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.cache.interceptor.BeanFactoryCacheOperationSourceAdvisor;
import org.springframework.cache.interceptor.CacheInterceptor;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
@@ -79,8 +79,7 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser
* register an AutoProxyCreator} with the container as necessary.
*/
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
public @Nullable BeanDefinition parse(Element element, ParserContext parserContext) {
String mode = element.getAttribute("mode");
if ("aspectj".equals(mode)) {
// mode="aspectj"

View File

@@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.jspecify.annotations.Nullable;
import org.w3c.dom.Element;
import org.springframework.beans.factory.config.TypedStringValue;
@@ -36,7 +37,6 @@ import org.springframework.cache.interceptor.CacheOperation;
import org.springframework.cache.interceptor.CachePutOperation;
import org.springframework.cache.interceptor.CacheableOperation;
import org.springframework.cache.interceptor.NameMatchCacheOperationSource;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
@@ -185,8 +185,7 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
private final String method;
@Nullable
private String[] caches;
private String @Nullable [] caches;
Props(Element root) {
String defaultCache = root.getAttribute("cache");
@@ -231,8 +230,7 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
return builder;
}
@Nullable
String merge(Element element, ReaderContext readerCtx) {
@Nullable String merge(Element element, ReaderContext readerCtx) {
String method = element.getAttribute(METHOD_ATTRIBUTE);
if (StringUtils.hasText(method)) {
return method.trim();

View File

@@ -4,9 +4,7 @@
* org.springframework.cache.annotation.EnableCaching EnableCaching}
* for details on code-based configuration without XML.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.cache.config;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -20,8 +20,9 @@ import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
import org.jspecify.annotations.Nullable;
import org.springframework.cache.Cache;
import org.springframework.lang.Nullable;
import org.springframework.util.function.SingletonSupplier;
/**
@@ -72,8 +73,7 @@ public abstract class AbstractCacheInvoker {
* miss in case of error.
* @see Cache#get(Object)
*/
@Nullable
protected Cache.ValueWrapper doGet(Cache cache, Object key) {
protected Cache.@Nullable ValueWrapper doGet(Cache cache, Object key) {
try {
return cache.get(key);
}
@@ -91,8 +91,7 @@ public abstract class AbstractCacheInvoker {
* @since 6.2
* @see Cache#get(Object, Callable)
*/
@Nullable
protected <T> T doGet(Cache cache, Object key, Callable<T> valueLoader) {
protected <T> @Nullable T doGet(Cache cache, Object key, Callable<T> valueLoader) {
try {
return cache.get(key, valueLoader);
}
@@ -119,8 +118,7 @@ public abstract class AbstractCacheInvoker {
* @since 6.2
* @see Cache#retrieve(Object)
*/
@Nullable
protected CompletableFuture<?> doRetrieve(Cache cache, Object key) {
protected @Nullable CompletableFuture<?> doRetrieve(Cache cache, Object key) {
try {
return cache.retrieve(key);
}

View File

@@ -20,10 +20,11 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -37,8 +38,7 @@ import org.springframework.util.Assert;
*/
public abstract class AbstractCacheResolver implements CacheResolver, InitializingBean {
@Nullable
private CacheManager cacheManager;
private @Nullable CacheManager cacheManager;
/**
@@ -103,7 +103,6 @@ public abstract class AbstractCacheResolver implements CacheResolver, Initializi
* @param context the context of the particular invocation
* @return the cache name(s) to resolve, or {@code null} if no cache should be resolved
*/
@Nullable
protected abstract Collection<String> getCacheNames(CacheOperationInvocationContext<?> context);
protected abstract @Nullable Collection<String> getCacheNames(CacheOperationInvocationContext<?> context);
}

View File

@@ -25,10 +25,10 @@ import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.aop.support.AopUtils;
import org.springframework.core.MethodClassKey;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ReflectionUtils;
@@ -78,8 +78,7 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera
}
@Override
@Nullable
public Collection<CacheOperation> getCacheOperations(Method method, @Nullable Class<?> targetClass) {
public @Nullable Collection<CacheOperation> getCacheOperations(Method method, @Nullable Class<?> targetClass) {
return getCacheOperations(method, targetClass, true);
}
@@ -92,8 +91,7 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera
* @return {@link CacheOperation} for this method, or {@code null} if the method
* is not cacheable
*/
@Nullable
private Collection<CacheOperation> getCacheOperations(
private @Nullable Collection<CacheOperation> getCacheOperations(
Method method, @Nullable Class<?> targetClass, boolean cacheNull) {
if (ReflectionUtils.isObjectMethod(method)) {
@@ -133,8 +131,7 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera
return new MethodClassKey(method, targetClass);
}
@Nullable
private Collection<CacheOperation> computeCacheOperations(Method method, @Nullable Class<?> targetClass) {
private @Nullable Collection<CacheOperation> computeCacheOperations(Method method, @Nullable Class<?> targetClass) {
// Don't allow non-public methods, as configured.
if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) {
return null;
@@ -179,8 +176,7 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera
* @param clazz the class to retrieve the cache operations for
* @return all cache operations associated with this class, or {@code null} if none
*/
@Nullable
protected abstract Collection<CacheOperation> findCacheOperations(Class<?> clazz);
protected abstract @Nullable Collection<CacheOperation> findCacheOperations(Class<?> clazz);
/**
* Subclasses need to implement this to return the cache operations for the
@@ -188,8 +184,7 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera
* @param method the method to retrieve the cache operations for
* @return all cache operations associated with this method, or {@code null} if none
*/
@Nullable
protected abstract Collection<CacheOperation> findCacheOperations(Method method);
protected abstract @Nullable Collection<CacheOperation> findCacheOperations(Method method);
/**
* Should only public methods be allowed to have caching semantics?

View File

@@ -30,6 +30,7 @@ import java.util.function.Supplier;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import reactor.core.publisher.Flux;
@@ -55,7 +56,6 @@ import org.springframework.core.ReactiveAdapterRegistry;
import org.springframework.core.SpringProperties;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
@@ -129,19 +129,15 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
private final CacheOperationExpressionEvaluator evaluator = new CacheOperationExpressionEvaluator(
new CacheEvaluationContextFactory(this.originalEvaluationContext));
@Nullable
private final ReactiveCachingHandler reactiveCachingHandler;
private final @Nullable ReactiveCachingHandler reactiveCachingHandler;
@Nullable
private CacheOperationSource cacheOperationSource;
private @Nullable CacheOperationSource cacheOperationSource;
private SingletonSupplier<KeyGenerator> keyGenerator = SingletonSupplier.of(SimpleKeyGenerator::new);
@Nullable
private SingletonSupplier<CacheResolver> cacheResolver;
private @Nullable SingletonSupplier<CacheResolver> cacheResolver;
@Nullable
private BeanFactory beanFactory;
private @Nullable BeanFactory beanFactory;
private boolean initialized = false;
@@ -192,8 +188,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
/**
* Return the CacheOperationSource for this cache aspect.
*/
@Nullable
public CacheOperationSource getCacheOperationSource() {
public @Nullable CacheOperationSource getCacheOperationSource() {
return this.cacheOperationSource;
}
@@ -228,8 +223,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
/**
* Return the default {@link CacheResolver} that this cache aspect delegates to.
*/
@Nullable
public CacheResolver getCacheResolver() {
public @Nullable CacheResolver getCacheResolver() {
return SupplierUtils.resolve(this.cacheResolver);
}
@@ -397,8 +391,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
this.evaluator.clear();
}
@Nullable
protected Object execute(CacheOperationInvoker invoker, Object target, Method method, Object[] args) {
protected @Nullable Object execute(CacheOperationInvoker invoker, Object target, Method method, 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);
@@ -425,13 +418,11 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
* @return the result of the invocation
* @see CacheOperationInvoker#invoke()
*/
@Nullable
protected Object invokeOperation(CacheOperationInvoker invoker) {
protected @Nullable Object invokeOperation(CacheOperationInvoker invoker) {
return invoker.invoke();
}
@Nullable
private Object execute(CacheOperationInvoker invoker, Method method, CacheOperationContexts contexts) {
private @Nullable Object execute(CacheOperationInvoker invoker, Method method, CacheOperationContexts contexts) {
if (contexts.isSynchronized()) {
// Special handling of synchronized invocation
return executeSynchronized(invoker, method, contexts);
@@ -449,8 +440,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
return cacheHit;
}
@Nullable
private Object executeSynchronized(CacheOperationInvoker invoker, Method method, CacheOperationContexts contexts) {
private @Nullable Object executeSynchronized(CacheOperationInvoker invoker, Method method, CacheOperationContexts contexts) {
CacheOperationContext context = contexts.get(CacheableOperation.class).iterator().next();
if (isConditionPassing(context, CacheOperationExpressionEvaluator.NO_RESULT)) {
Object key = generateKey(context, CacheOperationExpressionEvaluator.NO_RESULT);
@@ -487,8 +477,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
* @return a {@link Cache.ValueWrapper} holding the cached value,
* or {@code null} if none is found
*/
@Nullable
private Object findCachedValue(CacheOperationInvoker invoker, Method method, CacheOperationContexts contexts) {
private @Nullable Object findCachedValue(CacheOperationInvoker invoker, Method method, CacheOperationContexts contexts) {
for (CacheOperationContext context : contexts.get(CacheableOperation.class)) {
if (isConditionPassing(context, CacheOperationExpressionEvaluator.NO_RESULT)) {
Object key = generateKey(context, CacheOperationExpressionEvaluator.NO_RESULT);
@@ -509,8 +498,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
return null;
}
@Nullable
private Object findInCaches(CacheOperationContext context, Object key,
private @Nullable Object findInCaches(CacheOperationContext context, Object key,
CacheOperationInvoker invoker, Method method, CacheOperationContexts contexts) {
for (Cache cache : context.getCaches()) {
@@ -543,8 +531,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
return null;
}
@Nullable
private Object evaluate(@Nullable Object cacheHit, CacheOperationInvoker invoker, Method method,
private @Nullable Object evaluate(@Nullable Object cacheHit, CacheOperationInvoker invoker, Method method,
CacheOperationContexts contexts) {
// Re-invocation in reactive pipeline after late cache hit determination?
@@ -596,13 +583,11 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
return returnValue;
}
@Nullable
private Object unwrapCacheValue(@Nullable Object cacheValue) {
private @Nullable Object unwrapCacheValue(@Nullable Object cacheValue) {
return (cacheValue instanceof Cache.ValueWrapper wrapper ? wrapper.get() : cacheValue);
}
@Nullable
private Object wrapCacheValue(Method method, @Nullable Object cacheValue) {
private @Nullable Object wrapCacheValue(Method method, @Nullable Object cacheValue) {
if (method.getReturnType() == Optional.class &&
(cacheValue == null || cacheValue.getClass() != Optional.class)) {
return Optional.ofNullable(cacheValue);
@@ -610,8 +595,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
return cacheValue;
}
@Nullable
private Object unwrapReturnValue(@Nullable Object returnValue) {
private @Nullable Object unwrapReturnValue(@Nullable Object returnValue) {
return ObjectUtils.unwrapOptional(returnValue);
}
@@ -633,8 +617,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
return (cachePutContexts.size() != excluded.size());
}
@Nullable
private Object processCacheEvicts(Collection<CacheOperationContext> contexts, boolean beforeInvocation,
private @Nullable Object processCacheEvicts(Collection<CacheOperationContext> contexts, boolean beforeInvocation,
@Nullable Object result) {
if (contexts.isEmpty()) {
@@ -841,7 +824,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
private final CacheOperationMetadata metadata;
private final Object[] args;
private final @Nullable Object[] args;
private final Object target;
@@ -849,13 +832,11 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
private final Collection<String> cacheNames;
@Nullable
private Boolean conditionPassing;
private @Nullable Boolean conditionPassing;
@Nullable
private Object key;
private @Nullable Object key;
public CacheOperationContext(CacheOperationMetadata metadata, Object[] args, Object target) {
public CacheOperationContext(CacheOperationMetadata metadata, @Nullable Object[] args, Object target) {
this.metadata = metadata;
this.args = extractArgs(metadata.method, args);
this.target = target;
@@ -879,11 +860,11 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
}
@Override
public Object[] getArgs() {
public @Nullable Object[] getArgs() {
return this.args;
}
private Object[] extractArgs(Method method, Object[] args) {
private @Nullable Object[] extractArgs(Method method, @Nullable Object[] args) {
if (!method.isVarArgs()) {
return args;
}
@@ -926,8 +907,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
/**
* Compute the key for the given caching operation.
*/
@Nullable
protected Object generateKey(@Nullable Object result) {
protected @Nullable Object generateKey(@Nullable Object result) {
if (StringUtils.hasText(this.metadata.operation.getKey())) {
EvaluationContext evaluationContext = createEvaluationContext(result);
this.key = evaluator.key(this.metadata.operation.getKey(), this.metadata.methodKey, evaluationContext);
@@ -943,8 +923,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
* @return generated key
* @since 6.1.2
*/
@Nullable
protected Object getGeneratedKey() {
protected @Nullable Object getGeneratedKey() {
return this.key;
}
@@ -1018,8 +997,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
this.context = context;
}
@Nullable
public Object apply(@Nullable Object result) {
public @Nullable Object apply(@Nullable Object result) {
if (result instanceof CompletableFuture<?> future) {
return future.whenComplete((value, ex) -> {
if (ex == null) {
@@ -1097,8 +1075,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
private final ReactiveAdapterRegistry registry = ReactiveAdapterRegistry.getSharedInstance();
@Nullable
public Object executeSynchronized(CacheOperationInvoker invoker, Method method, Cache cache, Object key) {
public @Nullable Object executeSynchronized(CacheOperationInvoker invoker, Method method, Cache cache, Object key) {
ReactiveAdapter adapter = this.registry.getAdapter(method.getReturnType());
if (adapter != null) {
if (adapter.isMultiValue()) {
@@ -1127,8 +1104,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
return NOT_HANDLED;
}
@Nullable
public Object processCacheEvicts(List<CacheOperationContext> contexts, @Nullable Object result) {
public @Nullable Object processCacheEvicts(List<CacheOperationContext> contexts, @Nullable Object result) {
ReactiveAdapter adapter = (result != null ? this.registry.getAdapter(result.getClass()) : null);
if (adapter != null) {
return adapter.fromPublisher(Mono.from(adapter.toPublisher(result))
@@ -1138,8 +1114,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Nullable
public Object findInCaches(CacheOperationContext context, Cache cache, Object key,
public @Nullable Object findInCaches(CacheOperationContext context, Cache cache, Object key,
CacheOperationInvoker invoker, Method method, CacheOperationContexts contexts) {
ReactiveAdapter adapter = this.registry.getAdapter(context.getMethod().getReturnType());
@@ -1188,8 +1163,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
(data != null ? Flux.just(data) : Flux.empty()));
}
@Nullable
public Object processPutRequest(CachePutRequest request, @Nullable Object result) {
public @Nullable Object processPutRequest(CachePutRequest request, @Nullable Object result) {
ReactiveAdapter adapter = (result != null ? this.registry.getAdapter(result.getClass()) : null);
if (adapter != null) {
if (adapter.isMultiValue()) {

View File

@@ -16,8 +16,9 @@
package org.springframework.cache.interceptor;
import org.jspecify.annotations.Nullable;
import org.springframework.cache.Cache;
import org.springframework.lang.Nullable;
/**
* A strategy for handling cache-related errors. In most cases, any

View File

@@ -20,9 +20,10 @@ import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.context.expression.MethodBasedEvaluationContext;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.lang.Nullable;
/**
* Cache-specific evaluation context that adds method parameters as SpEL
@@ -47,7 +48,7 @@ class CacheEvaluationContext extends MethodBasedEvaluationContext {
private final Set<String> unavailableVariables = new HashSet<>(1);
CacheEvaluationContext(Object rootObject, Method method, Object[] arguments,
CacheEvaluationContext(Object rootObject, Method method, @Nullable Object[] arguments,
ParameterNameDiscoverer parameterNameDiscoverer) {
super(rootObject, method, arguments, parameterNameDiscoverer);
@@ -70,8 +71,7 @@ class CacheEvaluationContext extends MethodBasedEvaluationContext {
* Load the param information only when needed.
*/
@Override
@Nullable
public Object lookupVariable(String name) {
public @Nullable Object lookupVariable(String name) {
if (this.unavailableVariables.contains(name)) {
throw new VariableNotAvailableException(name);
}

View File

@@ -19,10 +19,11 @@ package org.springframework.cache.interceptor;
import java.lang.reflect.Method;
import java.util.function.Supplier;
import org.jspecify.annotations.Nullable;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.lang.Nullable;
import org.springframework.util.function.SingletonSupplier;
/**
@@ -36,8 +37,7 @@ class CacheEvaluationContextFactory {
private final StandardEvaluationContext originalContext;
@Nullable
private Supplier<ParameterNameDiscoverer> parameterNameDiscoverer;
private @Nullable Supplier<ParameterNameDiscoverer> parameterNameDiscoverer;
CacheEvaluationContextFactory(StandardEvaluationContext originalContext) {
this.originalContext = originalContext;
@@ -62,7 +62,7 @@ class CacheEvaluationContextFactory {
* @return a context suitable for this cache operation
*/
public CacheEvaluationContext forOperation(CacheExpressionRootObject rootObject,
Method targetMethod, Object[] args) {
Method targetMethod, @Nullable Object[] args) {
CacheEvaluationContext evaluationContext = new CacheEvaluationContext(
rootObject, targetMethod, args, getParameterNameDiscoverer());

View File

@@ -19,6 +19,8 @@ package org.springframework.cache.interceptor;
import java.lang.reflect.Method;
import java.util.Collection;
import org.jspecify.annotations.Nullable;
import org.springframework.cache.Cache;
/**
@@ -34,7 +36,7 @@ class CacheExpressionRootObject {
private final Method method;
private final Object[] args;
private final @Nullable Object[] args;
private final Object target;
@@ -42,7 +44,7 @@ class CacheExpressionRootObject {
public CacheExpressionRootObject(
Collection<? extends Cache> caches, Method method, Object[] args, Object target, Class<?> targetClass) {
Collection<? extends Cache> caches, Method method, @Nullable Object[] args, Object target, Class<?> targetClass) {
this.method = method;
this.target = target;
@@ -64,7 +66,7 @@ class CacheExpressionRootObject {
return this.method.getName();
}
public Object[] getArgs() {
public @Nullable Object[] getArgs() {
return this.args;
}

View File

@@ -21,8 +21,8 @@ import java.lang.reflect.Method;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -46,8 +46,7 @@ import org.springframework.util.Assert;
public class CacheInterceptor extends CacheAspectSupport implements MethodInterceptor, Serializable {
@Override
@Nullable
public Object invoke(final MethodInvocation invocation) throws Throwable {
public @Nullable Object invoke(final MethodInvocation invocation) throws Throwable {
Method method = invocation.getMethod();
CacheOperationInvoker aopAllianceInvoker = () -> {

View File

@@ -19,7 +19,8 @@ package org.springframework.cache.interceptor;
import java.util.Collections;
import java.util.Set;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

View File

@@ -21,12 +21,13 @@ import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.jspecify.annotations.Nullable;
import org.springframework.cache.Cache;
import org.springframework.context.expression.AnnotatedElementKey;
import org.springframework.context.expression.CachedExpressionEvaluator;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.lang.Nullable;
/**
* Utility class handling the SpEL expression parsing.
@@ -85,7 +86,7 @@ class CacheOperationExpressionEvaluator extends CachedExpressionEvaluator {
* @return the evaluation context
*/
public EvaluationContext createEvaluationContext(Collection<? extends Cache> caches,
Method method, Object[] args, Object target, Class<?> targetClass, Method targetMethod,
Method method, @Nullable Object[] args, Object target, Class<?> targetClass, Method targetMethod,
@Nullable Object result) {
CacheExpressionRootObject rootObject = new CacheExpressionRootObject(
@@ -101,8 +102,7 @@ class CacheOperationExpressionEvaluator extends CachedExpressionEvaluator {
return evaluationContext;
}
@Nullable
public Object key(String keyExpression, AnnotatedElementKey methodKey, EvaluationContext evalContext) {
public @Nullable Object key(String keyExpression, AnnotatedElementKey methodKey, EvaluationContext evalContext) {
return getExpression(this.keyCache, methodKey, keyExpression).getValue(evalContext);
}

View File

@@ -18,6 +18,8 @@ package org.springframework.cache.interceptor;
import java.lang.reflect.Method;
import org.jspecify.annotations.Nullable;
/**
* Representation of the context of the invocation of a cache operation.
*
@@ -48,6 +50,6 @@ public interface CacheOperationInvocationContext<O extends BasicOperation> {
/**
* Return the argument list used to invoke the method.
*/
Object[] getArgs();
@Nullable Object[] getArgs();
}

View File

@@ -16,7 +16,7 @@
package org.springframework.cache.interceptor;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Abstract the invocation of a cache operation.
@@ -38,8 +38,7 @@ public interface CacheOperationInvoker {
* @return the result of the operation
* @throws ThrowableWrapper if an error occurred while invoking the operation
*/
@Nullable
Object invoke() throws ThrowableWrapper;
@Nullable Object invoke() throws ThrowableWrapper;
/**

View File

@@ -19,7 +19,8 @@ package org.springframework.cache.interceptor;
import java.lang.reflect.Method;
import java.util.Collection;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.util.CollectionUtils;
/**
@@ -72,7 +73,6 @@ public interface CacheOperationSource {
* the declaring class of the method must be used)
* @return all cache operations for this method, or {@code null} if none found
*/
@Nullable
Collection<CacheOperation> getCacheOperations(Method method, @Nullable Class<?> targetClass);
@Nullable Collection<CacheOperation> getCacheOperations(Method method, @Nullable Class<?> targetClass);
}

View File

@@ -19,10 +19,11 @@ package org.springframework.cache.interceptor;
import java.io.Serializable;
import java.lang.reflect.Method;
import org.jspecify.annotations.Nullable;
import org.springframework.aop.ClassFilter;
import org.springframework.aop.support.StaticMethodMatcherPointcut;
import org.springframework.cache.CacheManager;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
/**
@@ -37,8 +38,7 @@ import org.springframework.util.ObjectUtils;
@SuppressWarnings("serial")
final class CacheOperationSourcePointcut extends StaticMethodMatcherPointcut implements Serializable {
@Nullable
private CacheOperationSource cacheOperationSource;
private @Nullable CacheOperationSource cacheOperationSource;
public CacheOperationSourcePointcut() {
@@ -87,8 +87,7 @@ final class CacheOperationSourcePointcut extends StaticMethodMatcherPointcut imp
return (cacheOperationSource == null || cacheOperationSource.isCandidateClass(clazz));
}
@Nullable
private CacheOperationSource getCacheOperationSource() {
private @Nullable CacheOperationSource getCacheOperationSource() {
return cacheOperationSource;
}

View File

@@ -16,7 +16,7 @@
package org.springframework.cache.interceptor;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Class describing a cache 'put' operation.
@@ -28,8 +28,7 @@ import org.springframework.lang.Nullable;
*/
public class CachePutOperation extends CacheOperation {
@Nullable
private final String unless;
private final @Nullable String unless;
/**
@@ -42,8 +41,7 @@ public class CachePutOperation extends CacheOperation {
}
@Nullable
public String getUnless() {
public @Nullable String getUnless() {
return this.unless;
}
@@ -54,8 +52,7 @@ public class CachePutOperation extends CacheOperation {
*/
public static class Builder extends CacheOperation.Builder {
@Nullable
private String unless;
private @Nullable String unless;
public void setUnless(String unless) {
this.unless = unless;

View File

@@ -16,7 +16,7 @@
package org.springframework.cache.interceptor;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Class describing a cache 'cacheable' operation.
@@ -28,8 +28,7 @@ import org.springframework.lang.Nullable;
*/
public class CacheableOperation extends CacheOperation {
@Nullable
private final String unless;
private final @Nullable String unless;
private final boolean sync;
@@ -45,8 +44,7 @@ public class CacheableOperation extends CacheOperation {
}
@Nullable
public String getUnless() {
public @Nullable String getUnless() {
return this.unless;
}
@@ -61,8 +59,7 @@ public class CacheableOperation extends CacheOperation {
*/
public static class Builder extends CacheOperation.Builder {
@Nullable
private String unless;
private @Nullable String unless;
private boolean sync;

View File

@@ -21,7 +21,8 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert;
/**
@@ -77,8 +78,7 @@ public class CompositeCacheOperationSource implements CacheOperationSource, Seri
}
@Override
@Nullable
public Collection<CacheOperation> getCacheOperations(Method method, @Nullable Class<?> targetClass) {
public @Nullable Collection<CacheOperation> getCacheOperations(Method method, @Nullable Class<?> targetClass) {
Collection<CacheOperation> ops = null;
for (CacheOperationSource source : this.cacheOperationSources) {
Collection<CacheOperation> cacheOperations = source.getCacheOperations(method, targetClass);

View File

@@ -18,6 +18,8 @@ package org.springframework.cache.interceptor;
import java.lang.reflect.Method;
import org.jspecify.annotations.Nullable;
/**
* Cache key generator. Used for creating a key based on the given method
* (used as context) and its parameters.
@@ -37,6 +39,6 @@ public interface KeyGenerator {
* @param params the method parameters (with any var-args expanded)
* @return a generated key
*/
Object generate(Object target, Method method, Object... params);
Object generate(Object target, Method method, @Nullable Object... params);
}

View File

@@ -20,9 +20,9 @@ import java.util.function.Supplier;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.cache.Cache;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**

View File

@@ -24,8 +24,8 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
import org.springframework.util.PatternMatchUtils;
@@ -75,8 +75,7 @@ public class NameMatchCacheOperationSource implements CacheOperationSource, Seri
}
@Override
@Nullable
public Collection<CacheOperation> getCacheOperations(Method method, @Nullable Class<?> targetClass) {
public @Nullable Collection<CacheOperation> getCacheOperations(Method method, @Nullable Class<?> targetClass) {
// look for direct name match
String methodName = method.getName();
Collection<CacheOperation> ops = this.nameMap.get(methodName);

View File

@@ -19,8 +19,9 @@ package org.springframework.cache.interceptor;
import java.util.Collection;
import java.util.List;
import org.jspecify.annotations.Nullable;
import org.springframework.cache.CacheManager;
import org.springframework.lang.Nullable;
/**
* A {@link CacheResolver} that forces the resolution to a configurable
@@ -31,8 +32,7 @@ import org.springframework.lang.Nullable;
*/
public class NamedCacheResolver extends AbstractCacheResolver {
@Nullable
private Collection<String> cacheNames;
private @Nullable Collection<String> cacheNames;
public NamedCacheResolver() {
@@ -52,8 +52,7 @@ public class NamedCacheResolver extends AbstractCacheResolver {
}
@Override
@Nullable
protected Collection<String> getCacheNames(CacheOperationInvocationContext<?> context) {
protected @Nullable Collection<String> getCacheNames(CacheOperationInvocationContext<?> context) {
return this.cacheNames;
}

View File

@@ -16,8 +16,9 @@
package org.springframework.cache.interceptor;
import org.jspecify.annotations.Nullable;
import org.springframework.cache.Cache;
import org.springframework.lang.Nullable;
/**
* A simple {@link CacheErrorHandler} that does not handle the

View File

@@ -18,9 +18,10 @@ package org.springframework.cache.interceptor;
import java.util.Collection;
import org.jspecify.annotations.Nullable;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.lang.Nullable;
/**
* A simple {@link CacheResolver} that resolves the {@link Cache} instance(s)
@@ -62,8 +63,7 @@ public class SimpleCacheResolver extends AbstractCacheResolver {
* @return the SimpleCacheResolver ({@code null} if the CacheManager was {@code null})
* @since 5.1
*/
@Nullable
static SimpleCacheResolver of(@Nullable CacheManager cacheManager) {
static @Nullable SimpleCacheResolver of(@Nullable CacheManager cacheManager) {
return (cacheManager != null ? new SimpleCacheResolver(cacheManager) : null);
}

View File

@@ -21,7 +21,8 @@ import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.Arrays;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert;
/**
@@ -41,7 +42,7 @@ public class SimpleKey implements Serializable {
public static final SimpleKey EMPTY = new SimpleKey();
private final Object[] params;
private final @Nullable Object[] params;
// Effectively final, just re-calculated on deserialization
private transient int hashCode;
@@ -51,7 +52,7 @@ public class SimpleKey implements Serializable {
* Create a new {@link SimpleKey} instance.
* @param elements the elements of the key
*/
public SimpleKey(Object... elements) {
public SimpleKey(@Nullable Object... elements) {
Assert.notNull(elements, "Elements must not be null");
this.params = elements.clone();
// Pre-calculate hashCode field

View File

@@ -19,6 +19,8 @@ package org.springframework.cache.interceptor;
import java.lang.reflect.Method;
import java.util.Arrays;
import org.jspecify.annotations.Nullable;
import org.springframework.core.KotlinDetector;
/**
@@ -41,7 +43,8 @@ import org.springframework.core.KotlinDetector;
public class SimpleKeyGenerator implements KeyGenerator {
@Override
public Object generate(Object target, Method method, Object... params) {
@SuppressWarnings("NullAway")
public Object generate(Object target, Method method, @Nullable Object... params) {
return generateKey((KotlinDetector.isSuspendingFunction(method) ?
Arrays.copyOf(params, params.length - 1) : params));
}
@@ -49,7 +52,7 @@ public class SimpleKeyGenerator implements KeyGenerator {
/**
* Generate a key based on the specified parameters.
*/
public static Object generateKey(Object... params) {
public static Object generateKey(@Nullable Object... params) {
if (params.length == 0) {
return SimpleKey.EMPTY;
}

View File

@@ -3,9 +3,7 @@
* Builds on the AOP infrastructure in org.springframework.aop.framework.
* Any POJO can be cache-advised with Spring.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.cache.interceptor;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -2,9 +2,7 @@
* Spring's generic cache abstraction.
* Concrete implementations are provided in the subpackages.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.cache;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -23,10 +23,11 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
/**
@@ -86,8 +87,7 @@ public abstract class AbstractCacheManager implements CacheManager, Initializing
// Lazy cache initialization on access
@Override
@Nullable
public Cache getCache(String name) {
public @Nullable Cache getCache(String name) {
// Quick check for existing cache...
Cache cache = this.cacheMap.get(name);
if (cache != null) {
@@ -128,8 +128,7 @@ public abstract class AbstractCacheManager implements CacheManager, Initializing
* @see #getCache(String)
* @see #getMissingCache(String)
*/
@Nullable
protected final Cache lookupCache(String name) {
protected final @Nullable Cache lookupCache(String name) {
return this.cacheMap.get(name);
}
@@ -172,8 +171,7 @@ public abstract class AbstractCacheManager implements CacheManager, Initializing
* @since 4.1
* @see #getCache(String)
*/
@Nullable
protected Cache getMissingCache(String name) {
protected @Nullable Cache getMissingCache(String name) {
return null;
}

View File

@@ -16,8 +16,9 @@
package org.springframework.cache.support;
import org.jspecify.annotations.Nullable;
import org.springframework.cache.Cache;
import org.springframework.lang.Nullable;
/**
* Common base class for {@link Cache} implementations that need to adapt
@@ -53,15 +54,13 @@ public abstract class AbstractValueAdaptingCache implements Cache {
}
@Override
@Nullable
public ValueWrapper get(Object key) {
public @Nullable ValueWrapper get(Object key) {
return toValueWrapper(lookup(key));
}
@Override
@SuppressWarnings("unchecked")
@Nullable
public <T> T get(Object key, @Nullable Class<T> type) {
public <T> @Nullable T get(Object key, @Nullable Class<T> type) {
Object value = fromStoreValue(lookup(key));
if (value != null && type != null && !type.isInstance(value)) {
throw new IllegalStateException(
@@ -75,8 +74,7 @@ public abstract class AbstractValueAdaptingCache implements Cache {
* @param key the key whose associated value is to be returned
* @return the raw store value for the key, or {@code null} if none
*/
@Nullable
protected abstract Object lookup(Object key);
protected abstract @Nullable Object lookup(Object key);
/**
@@ -85,8 +83,7 @@ public abstract class AbstractValueAdaptingCache implements Cache {
* @param storeValue the store value
* @return the value to return to the user
*/
@Nullable
protected Object fromStoreValue(@Nullable Object storeValue) {
protected @Nullable Object fromStoreValue(@Nullable Object storeValue) {
if (this.allowNullValues && storeValue == NullValue.INSTANCE) {
return null;
}
@@ -117,8 +114,7 @@ public abstract class AbstractValueAdaptingCache implements Cache {
* @param storeValue the original value
* @return the wrapped value
*/
@Nullable
protected Cache.ValueWrapper toValueWrapper(@Nullable Object storeValue) {
protected Cache.@Nullable ValueWrapper toValueWrapper(@Nullable Object storeValue) {
return (storeValue != null ? new SimpleValueWrapper(fromStoreValue(storeValue)) : null);
}

View File

@@ -24,10 +24,11 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.lang.Nullable;
/**
* Composite {@link CacheManager} implementation that iterates over
@@ -99,8 +100,7 @@ public class CompositeCacheManager implements CacheManager, InitializingBean {
@Override
@Nullable
public Cache getCache(String name) {
public @Nullable Cache getCache(String name) {
for (CacheManager cacheManager : this.cacheManagers) {
Cache cache = cacheManager.getCache(name);
if (cache != null) {

View File

@@ -20,8 +20,9 @@ import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
import org.jspecify.annotations.Nullable;
import org.springframework.cache.Cache;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -60,20 +61,17 @@ public class NoOpCache implements Cache {
}
@Override
@Nullable
public ValueWrapper get(Object key) {
public @Nullable ValueWrapper get(Object key) {
return null;
}
@Override
@Nullable
public <T> T get(Object key, @Nullable Class<T> type) {
public <T> @Nullable T get(Object key, @Nullable Class<T> type) {
return null;
}
@Override
@Nullable
public <T> T get(Object key, Callable<T> valueLoader) {
public <T> @Nullable T get(Object key, Callable<T> valueLoader) {
try {
return valueLoader.call();
}
@@ -83,8 +81,7 @@ public class NoOpCache implements Cache {
}
@Override
@Nullable
public CompletableFuture<?> retrieve(Object key) {
public @Nullable CompletableFuture<?> retrieve(Object key) {
return null;
}
@@ -98,8 +95,7 @@ public class NoOpCache implements Cache {
}
@Override
@Nullable
public ValueWrapper putIfAbsent(Object key, @Nullable Object value) {
public @Nullable ValueWrapper putIfAbsent(Object key, @Nullable Object value) {
return null;
}

View File

@@ -23,9 +23,10 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.jspecify.annotations.Nullable;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.lang.Nullable;
/**
* A basic, no operation {@link CacheManager} implementation suitable
@@ -51,8 +52,7 @@ public class NoOpCacheManager implements CacheManager {
* Additionally, the request cache will be remembered by the manager for consistency.
*/
@Override
@Nullable
public Cache getCache(String name) {
public @Nullable Cache getCache(String name) {
Cache cache = this.caches.get(name);
if (cache == null) {
this.caches.computeIfAbsent(name, NoOpCache::new);

View File

@@ -18,7 +18,7 @@ package org.springframework.cache.support;
import java.io.Serializable;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Simple serializable class that serves as a {@code null} replacement

View File

@@ -18,8 +18,9 @@ package org.springframework.cache.support;
import java.util.Objects;
import org.jspecify.annotations.Nullable;
import org.springframework.cache.Cache.ValueWrapper;
import org.springframework.lang.Nullable;
/**
* Straightforward implementation of {@link org.springframework.cache.Cache.ValueWrapper},
@@ -30,8 +31,7 @@ import org.springframework.lang.Nullable;
*/
public class SimpleValueWrapper implements ValueWrapper {
@Nullable
private final Object value;
private final @Nullable Object value;
/**
@@ -47,8 +47,7 @@ public class SimpleValueWrapper implements ValueWrapper {
* Simply returns the value as given at construction time.
*/
@Override
@Nullable
public Object get() {
public @Nullable Object get() {
return this.value;
}

View File

@@ -2,9 +2,7 @@
* Support classes for the org.springframework.cache package.
* Provides abstract classes for cache managers and caches.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.cache.support;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -16,12 +16,13 @@
package org.springframework.context;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.HierarchicalBeanFactory;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.core.env.EnvironmentCapable;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.lang.Nullable;
/**
* Central interface to provide configuration for an application.
@@ -62,8 +63,7 @@ public interface ApplicationContext extends EnvironmentCapable, ListableBeanFact
* Return the unique id of this application context.
* @return the unique id of the context, or {@code null} if none
*/
@Nullable
String getId();
@Nullable String getId();
/**
* Return a name for the deployed application that this context belongs to.
@@ -88,8 +88,7 @@ public interface ApplicationContext extends EnvironmentCapable, ListableBeanFact
* and this is the root of the context hierarchy.
* @return the parent context, or {@code null} if there is no parent
*/
@Nullable
ApplicationContext getParent();
@Nullable ApplicationContext getParent();
/**
* Expose AutowireCapableBeanFactory functionality for this context.

View File

@@ -19,6 +19,8 @@ package org.springframework.context;
import java.io.Closeable;
import java.util.concurrent.Executor;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
@@ -26,7 +28,6 @@ import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ProtocolResolver;
import org.springframework.core.metrics.ApplicationStartup;
import org.springframework.lang.Nullable;
/**
* SPI interface to be implemented by most if not all application contexts.

View File

@@ -16,7 +16,7 @@
package org.springframework.context;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Sub-interface of MessageSource to be implemented by objects that
@@ -39,7 +39,6 @@ public interface HierarchicalMessageSource extends MessageSource {
/**
* Return the parent of this MessageSource, or {@code null} if none.
*/
@Nullable
MessageSource getParentMessageSource();
@Nullable MessageSource getParentMessageSource();
}

View File

@@ -18,7 +18,7 @@ package org.springframework.context;
import java.util.Locale;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Strategy interface for resolving messages, with support for the parameterization
@@ -54,8 +54,7 @@ public interface MessageSource {
* @see #getMessage(MessageSourceResolvable, Locale)
* @see java.text.MessageFormat
*/
@Nullable
String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, Locale locale);
@Nullable String getMessage(String code, Object @Nullable [] args, @Nullable String defaultMessage, Locale locale);
/**
* Try to resolve the message. Treat as an error if the message can't be found.
@@ -71,7 +70,7 @@ public interface MessageSource {
* @see #getMessage(MessageSourceResolvable, Locale)
* @see java.text.MessageFormat
*/
String getMessage(String code, @Nullable Object[] args, Locale locale) throws NoSuchMessageException;
String getMessage(String code, Object @Nullable [] args, Locale locale) throws NoSuchMessageException;
/**
* Try to resolve the message using all the attributes contained within the

View File

@@ -16,7 +16,7 @@
package org.springframework.context;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Interface for objects that are suitable for message resolution in a
@@ -37,8 +37,7 @@ public interface MessageSourceResolvable {
* they should get tried. The last code will therefore be the default one.
* @return a String array of codes which are associated with this message
*/
@Nullable
String[] getCodes();
String @Nullable [] getCodes();
/**
* Return the array of arguments to be used to resolve this message.
@@ -47,8 +46,7 @@ public interface MessageSourceResolvable {
* placeholders within the message text
* @see java.text.MessageFormat
*/
@Nullable
default Object[] getArguments() {
default Object @Nullable [] getArguments() {
return null;
}
@@ -61,8 +59,7 @@ public interface MessageSourceResolvable {
* for this particular message.
* @return the default message, or {@code null} if no default
*/
@Nullable
default String getDefaultMessage() {
default @Nullable String getDefaultMessage() {
return null;
}

View File

@@ -18,9 +18,10 @@ package org.springframework.context;
import java.util.function.Consumer;
import org.jspecify.annotations.Nullable;
import org.springframework.core.ResolvableType;
import org.springframework.core.ResolvableTypeProvider;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**

View File

@@ -18,10 +18,11 @@ package org.springframework.context.annotation;
import java.lang.annotation.Annotation;
import org.jspecify.annotations.Nullable;
import org.springframework.core.GenericTypeResolver;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -92,7 +93,6 @@ public abstract class AdviceModeImportSelector<A extends Annotation> implements
* @return array containing classes to import (empty array if none;
* {@code null} if the given {@code AdviceMode} is unknown)
*/
@Nullable
protected abstract String[] selectImports(AdviceMode adviceMode);
protected abstract String @Nullable [] selectImports(AdviceMode adviceMode);
}

View File

@@ -19,6 +19,8 @@ package org.springframework.context.annotation;
import java.lang.annotation.Annotation;
import java.util.function.Supplier;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionCustomizer;
@@ -30,7 +32,6 @@ import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.core.env.Environment;
import org.springframework.core.env.EnvironmentCapable;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -247,8 +248,8 @@ public class AnnotatedBeanDefinitionReader {
* @since 5.0
*/
private <T> void doRegisterBean(Class<T> beanClass, @Nullable String name,
@Nullable Class<? extends Annotation>[] qualifiers, @Nullable Supplier<T> supplier,
@Nullable BeanDefinitionCustomizer[] customizers) {
Class<? extends Annotation> @Nullable [] qualifiers, @Nullable Supplier<T> supplier,
BeanDefinitionCustomizer @Nullable [] customizers) {
AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(beanClass);
if (this.conditionEvaluator.shouldSkip(abd.getMetadata())) {

View File

@@ -28,6 +28,7 @@ import java.util.stream.Collectors;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -38,7 +39,6 @@ import org.springframework.core.annotation.MergedAnnotation;
import org.springframework.core.annotation.MergedAnnotation.Adapt;
import org.springframework.core.annotation.MergedAnnotations;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
@@ -119,8 +119,7 @@ public class AnnotationBeanNameGenerator implements BeanNameGenerator {
* @param annotatedDef the annotation-aware bean definition
* @return the bean name, or {@code null} if none is found
*/
@Nullable
protected String determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotatedDef) {
protected @Nullable String determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotatedDef) {
AnnotationMetadata metadata = annotatedDef.getMetadata();
String beanName = getExplicitBeanName(metadata);
@@ -185,8 +184,7 @@ public class AnnotationBeanNameGenerator implements BeanNameGenerator {
* @since 6.1
* @see org.springframework.stereotype.Component#value()
*/
@Nullable
private String getExplicitBeanName(AnnotationMetadata metadata) {
private @Nullable String getExplicitBeanName(AnnotationMetadata metadata) {
List<String> names = metadata.getAnnotations().stream(COMPONENT_ANNOTATION_CLASSNAME)
.map(annotation -> annotation.getString(MergedAnnotation.VALUE))
.filter(StringUtils::hasText)

View File

@@ -19,13 +19,14 @@ package org.springframework.context.annotation;
import java.util.Arrays;
import java.util.function.Supplier;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.config.BeanDefinitionCustomizer;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.metrics.StartupStep;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**

View File

@@ -18,6 +18,7 @@ package org.springframework.context.annotation;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.w3c.dom.Element;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -26,7 +27,6 @@ import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.parsing.CompositeComponentDefinition;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.lang.Nullable;
/**
* Parser for the &lt;context:annotation-config/&gt; element.
@@ -40,8 +40,7 @@ import org.springframework.lang.Nullable;
public class AnnotationConfigBeanDefinitionParser implements BeanDefinitionParser {
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
public @Nullable BeanDefinition parse(Element element, ParserContext parserContext) {
Object source = parserContext.extractSource(element);
// Obtain bean definitions for all relevant BeanPostProcessors.

View File

@@ -20,6 +20,8 @@ import java.lang.annotation.Annotation;
import java.util.Set;
import java.util.function.Predicate;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -35,7 +37,6 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.core.annotation.MergedAnnotation;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
@@ -210,8 +211,7 @@ public abstract class AnnotationConfigUtils {
return new BeanDefinitionHolder(definition, beanName);
}
@Nullable
private static DefaultListableBeanFactory unwrapDefaultListableBeanFactory(BeanDefinitionRegistry registry) {
private static @Nullable DefaultListableBeanFactory unwrapDefaultListableBeanFactory(BeanDefinitionRegistry registry) {
if (registry instanceof DefaultListableBeanFactory dlbf) {
return dlbf;
}
@@ -271,13 +271,11 @@ public abstract class AnnotationConfigUtils {
return ScopedProxyCreator.createScopedProxy(definition, registry, proxyTargetClass);
}
@Nullable
static AnnotationAttributes attributesFor(AnnotatedTypeMetadata metadata, Class<?> annotationType) {
static @Nullable AnnotationAttributes attributesFor(AnnotatedTypeMetadata metadata, Class<?> annotationType) {
return attributesFor(metadata, annotationType.getName());
}
@Nullable
static AnnotationAttributes attributesFor(AnnotatedTypeMetadata metadata, String annotationTypeName) {
static @Nullable AnnotationAttributes attributesFor(AnnotatedTypeMetadata metadata, String annotationTypeName) {
return AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(annotationTypeName));
}

View File

@@ -18,11 +18,12 @@ package org.springframework.context.annotation;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.parsing.Problem;
import org.springframework.beans.factory.parsing.ProblemReporter;
import org.springframework.core.type.MethodMetadata;
import org.springframework.lang.Nullable;
/**
* Represents a {@link Configuration @Configuration} class method annotated with

View File

@@ -19,6 +19,8 @@ package org.springframework.context.annotation;
import java.util.LinkedHashSet;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
@@ -31,7 +33,6 @@ import org.springframework.core.env.Environment;
import org.springframework.core.env.EnvironmentCapable;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.PatternMatchUtils;
@@ -66,8 +67,7 @@ public class ClassPathBeanDefinitionScanner extends ClassPathScanningCandidateCo
private BeanDefinitionDefaults beanDefinitionDefaults = new BeanDefinitionDefaults();
@Nullable
private String[] autowireCandidatePatterns;
private String @Nullable [] autowireCandidatePatterns;
private BeanNameGenerator beanNameGenerator = AnnotationBeanNameGenerator.INSTANCE;
@@ -199,7 +199,7 @@ public class ClassPathBeanDefinitionScanner extends ClassPathScanningCandidateCo
* Set the name-matching patterns for determining autowire candidates.
* @param autowireCandidatePatterns the patterns to match against
*/
public void setAutowireCandidatePatterns(@Nullable String... autowireCandidatePatterns) {
public void setAutowireCandidatePatterns(String @Nullable ... autowireCandidatePatterns) {
this.autowireCandidatePatterns = autowireCandidatePatterns;
}

View File

@@ -27,6 +27,7 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
@@ -54,7 +55,6 @@ import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.core.type.filter.AssignableTypeFilter;
import org.springframework.core.type.filter.TypeFilter;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Indexed;
@@ -116,20 +116,15 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC
private final List<TypeFilter> excludeFilters = new ArrayList<>();
@Nullable
private Environment environment;
private @Nullable Environment environment;
@Nullable
private ConditionEvaluator conditionEvaluator;
private @Nullable ConditionEvaluator conditionEvaluator;
@Nullable
private ResourcePatternResolver resourcePatternResolver;
private @Nullable ResourcePatternResolver resourcePatternResolver;
@Nullable
private MetadataReaderFactory metadataReaderFactory;
private @Nullable MetadataReaderFactory metadataReaderFactory;
@Nullable
private CandidateComponentsIndex componentsIndex;
private @Nullable CandidateComponentsIndex componentsIndex;
/**
@@ -255,8 +250,7 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC
/**
* Return the {@link BeanDefinitionRegistry} used by this scanner, if any.
*/
@Nullable
protected BeanDefinitionRegistry getRegistry() {
protected @Nullable BeanDefinitionRegistry getRegistry() {
return null;
}
@@ -368,8 +362,7 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC
* @since 5.0
* @see #indexSupportsIncludeFilter(TypeFilter)
*/
@Nullable
private String extractStereotype(TypeFilter filter) {
private @Nullable String extractStereotype(TypeFilter filter) {
if (filter instanceof AnnotationTypeFilter annotationTypeFilter) {
return annotationTypeFilter.getAnnotationType().getName();
}

View File

@@ -34,6 +34,8 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.jspecify.annotations.Nullable;
import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aot.generate.AccessControl;
@@ -68,7 +70,6 @@ import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.javapoet.ClassName;
import org.springframework.javapoet.CodeBlock;
import org.springframework.jndi.support.SimpleJndiBeanFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
@@ -146,11 +147,9 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
private static final Set<Class<? extends Annotation>> resourceAnnotationTypes = CollectionUtils.newLinkedHashSet(3);
@Nullable
private static final Class<? extends Annotation> jakartaResourceType;
private static final @Nullable Class<? extends Annotation> jakartaResourceType;
@Nullable
private static final Class<? extends Annotation> ejbAnnotationType;
private static final @Nullable Class<? extends Annotation> ejbAnnotationType;
static {
jakartaResourceType = loadAnnotationType("jakarta.annotation.Resource");
@@ -171,17 +170,13 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
private boolean alwaysUseJndiLookup = false;
@Nullable
private transient BeanFactory jndiFactory;
private transient @Nullable BeanFactory jndiFactory;
@Nullable
private transient BeanFactory resourceFactory;
private transient @Nullable BeanFactory resourceFactory;
@Nullable
private transient BeanFactory beanFactory;
private transient @Nullable BeanFactory beanFactory;
@Nullable
private transient StringValueResolver embeddedValueResolver;
private transient @Nullable StringValueResolver embeddedValueResolver;
private final transient Map<String, InjectionMetadata> injectionMetadataCache = new ConcurrentHashMap<>(256);
@@ -298,8 +293,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
}
@Override
@Nullable
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
BeanRegistrationAotContribution parentAotContribution = super.processAheadOfTime(registeredBean);
Class<?> beanClass = registeredBean.getBeanClass();
String beanName = registeredBean.getBeanName();
@@ -316,8 +310,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
return parentAotContribution;
}
@Nullable
private AutowireCandidateResolver getAutowireCandidateResolver(RegisteredBean registeredBean) {
private @Nullable AutowireCandidateResolver getAutowireCandidateResolver(RegisteredBean registeredBean) {
if (registeredBean.getBeanFactory() instanceof DefaultListableBeanFactory lbf) {
return lbf.getAutowireCandidateResolver();
}
@@ -335,8 +328,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
}
@Override
@Nullable
public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) {
public @Nullable Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) {
return null;
}
@@ -585,8 +577,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
@SuppressWarnings("unchecked")
@Nullable
private static Class<? extends Annotation> loadAnnotationType(String name) {
private static @Nullable Class<? extends Annotation> loadAnnotationType(String name) {
try {
return (Class<? extends Annotation>)
ClassUtils.forName(name, CommonAnnotationBeanPostProcessor.class.getClassLoader());
@@ -609,8 +600,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
protected Class<?> lookupType = Object.class;
@Nullable
protected String mappedName;
protected @Nullable String mappedName;
public LookupElement(Member member, @Nullable PropertyDescriptor pd) {
super(member, pd);
@@ -775,8 +765,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
private final Collection<LookupElement> lookupElements;
@Nullable
private final AutowireCandidateResolver candidateResolver;
private final @Nullable AutowireCandidateResolver candidateResolver;
AotContribution(Class<?> target, Collection<LookupElement> lookupElements,
@Nullable AutowireCandidateResolver candidateResolver) {

View File

@@ -20,6 +20,7 @@ import java.lang.annotation.Annotation;
import java.util.Set;
import java.util.regex.Pattern;
import org.jspecify.annotations.Nullable;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -39,7 +40,6 @@ import org.springframework.core.type.filter.AspectJTypeFilter;
import org.springframework.core.type.filter.AssignableTypeFilter;
import org.springframework.core.type.filter.RegexPatternTypeFilter;
import org.springframework.core.type.filter.TypeFilter;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
@@ -79,8 +79,7 @@ public class ComponentScanBeanDefinitionParser implements BeanDefinitionParser {
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
public @Nullable BeanDefinition parse(Element element, ParserContext parserContext) {
String basePackage = element.getAttribute(BASE_PACKAGE_ATTRIBUTE);
basePackage = parserContext.getReaderContext().getEnvironment().resolvePlaceholders(basePackage);
String[] basePackages = StringUtils.tokenizeToStringArray(basePackage,

View File

@@ -16,11 +16,12 @@
package org.springframework.context.annotation;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.lang.Nullable;
/**
* Context information for use by {@link Condition} implementations.
@@ -44,8 +45,7 @@ public interface ConditionContext {
* definition should the condition match, or {@code null} if the bean factory is
* not available (or not downcastable to {@code ConfigurableListableBeanFactory}).
*/
@Nullable
ConfigurableListableBeanFactory getBeanFactory();
@Nullable ConfigurableListableBeanFactory getBeanFactory();
/**
* Return the {@link Environment} for which the current application is running.
@@ -62,7 +62,6 @@ public interface ConditionContext {
* (only {@code null} if even the system ClassLoader isn't accessible).
* @see org.springframework.util.ClassUtils#forName(String, ClassLoader)
*/
@Nullable
ClassLoader getClassLoader();
@Nullable ClassLoader getClassLoader();
}

View File

@@ -20,6 +20,8 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
@@ -33,7 +35,6 @@ import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.MultiValueMap;
@@ -144,18 +145,15 @@ class ConditionEvaluator {
*/
private static class ConditionContextImpl implements ConditionContext {
@Nullable
private final BeanDefinitionRegistry registry;
private final @Nullable BeanDefinitionRegistry registry;
@Nullable
private final ConfigurableListableBeanFactory beanFactory;
private final @Nullable ConfigurableListableBeanFactory beanFactory;
private final Environment environment;
private final ResourceLoader resourceLoader;
@Nullable
private final ClassLoader classLoader;
private final @Nullable ClassLoader classLoader;
public ConditionContextImpl(@Nullable BeanDefinitionRegistry registry,
@Nullable Environment environment, @Nullable ResourceLoader resourceLoader) {
@@ -167,8 +165,7 @@ class ConditionEvaluator {
this.classLoader = deduceClassLoader(resourceLoader, this.beanFactory);
}
@Nullable
private static ConfigurableListableBeanFactory deduceBeanFactory(@Nullable BeanDefinitionRegistry source) {
private static @Nullable ConfigurableListableBeanFactory deduceBeanFactory(@Nullable BeanDefinitionRegistry source) {
if (source instanceof ConfigurableListableBeanFactory configurableListableBeanFactory) {
return configurableListableBeanFactory;
}
@@ -192,8 +189,7 @@ class ConditionEvaluator {
return new DefaultResourceLoader();
}
@Nullable
private static ClassLoader deduceClassLoader(@Nullable ResourceLoader resourceLoader,
private static @Nullable ClassLoader deduceClassLoader(@Nullable ResourceLoader resourceLoader,
@Nullable ConfigurableListableBeanFactory beanFactory) {
if (resourceLoader != null) {
@@ -215,8 +211,7 @@ class ConditionEvaluator {
}
@Override
@Nullable
public ConfigurableListableBeanFactory getBeanFactory() {
public @Nullable ConfigurableListableBeanFactory getBeanFactory() {
return this.beanFactory;
}
@@ -231,8 +226,7 @@ class ConditionEvaluator {
}
@Override
@Nullable
public ClassLoader getClassLoader() {
public @Nullable ClassLoader getClassLoader() {
return this.classLoader;
}
}

View File

@@ -22,6 +22,8 @@ import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.parsing.Location;
import org.springframework.beans.factory.parsing.Problem;
import org.springframework.beans.factory.parsing.ProblemReporter;
@@ -31,7 +33,6 @@ import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.MethodMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -53,8 +54,7 @@ final class ConfigurationClass {
private final Resource resource;
@Nullable
private String beanName;
private @Nullable String beanName;
private boolean scanned = false;
@@ -154,8 +154,7 @@ final class ConfigurationClass {
this.beanName = beanName;
}
@Nullable
String getBeanName() {
@Nullable String getBeanName() {
return this.beanName;
}

View File

@@ -26,6 +26,7 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.NonNull;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
@@ -51,7 +52,6 @@ import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.MethodMetadata;
import org.springframework.core.type.StandardAnnotationMetadata;
import org.springframework.core.type.StandardMethodMetadata;
import org.springframework.lang.NonNull;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
@@ -448,8 +448,7 @@ class ConfigurationClassBeanDefinitionReader {
}
@Override
@NonNull
public MethodMetadata getFactoryMethodMetadata() {
public @NonNull MethodMetadata getFactoryMethodMetadata() {
return this.factoryMethodMetadata;
}

View File

@@ -24,6 +24,7 @@ import java.util.Arrays;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.aop.scope.ScopedProxyFactoryBean;
import org.springframework.asm.Opcodes;
@@ -50,7 +51,6 @@ import org.springframework.cglib.proxy.NoOp;
import org.springframework.cglib.transform.ClassEmitterTransformer;
import org.springframework.cglib.transform.TransformingClassGenerator;
import org.springframework.core.SmartClassLoader;
import org.springframework.lang.Nullable;
import org.springframework.objenesis.ObjenesisException;
import org.springframework.objenesis.SpringObjenesis;
import org.springframework.util.Assert;
@@ -254,8 +254,7 @@ class ConfigurationClassEnhancer {
private static class BeanFactoryAwareMethodInterceptor implements MethodInterceptor, ConditionalCallback {
@Override
@Nullable
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
public @Nullable Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
Field field = ReflectionUtils.findField(obj.getClass(), BEAN_FACTORY_FIELD);
Assert.state(field != null, "Unable to find generated BeanFactory field");
field.set(obj, args[0]);
@@ -297,8 +296,7 @@ class ConfigurationClassEnhancer {
* super implementation of the proxied method i.e., the actual {@code @Bean} method
*/
@Override
@Nullable
public Object intercept(Object enhancedConfigInstance, Method beanMethod, Object[] beanMethodArgs,
public @Nullable Object intercept(Object enhancedConfigInstance, Method beanMethod, Object[] beanMethodArgs,
MethodProxy cglibMethodProxy) throws Throwable {
ConfigurableBeanFactory beanFactory = getBeanFactory(enhancedConfigInstance);
@@ -351,8 +349,7 @@ class ConfigurationClassEnhancer {
return resolveBeanReference(beanMethod, beanMethodArgs, beanFactory, beanName);
}
@Nullable
private Object resolveBeanReference(Method beanMethod, Object[] beanMethodArgs,
private @Nullable Object resolveBeanReference(Method beanMethod, Object[] beanMethodArgs,
ConfigurableBeanFactory beanFactory, String beanName) {
// The user (i.e. not the factory) is requesting this bean through a call to

View File

@@ -37,6 +37,7 @@ import java.util.function.Predicate;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
@@ -69,7 +70,6 @@ import org.springframework.core.type.StandardAnnotationMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.AssignableTypeFilter;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -122,8 +122,7 @@ class ConfigurationClassParser {
private final ResourceLoader resourceLoader;
@Nullable
private final PropertySourceRegistry propertySourceRegistry;
private final @Nullable PropertySourceRegistry propertySourceRegistry;
private final BeanDefinitionRegistry registry;
@@ -284,8 +283,7 @@ class ConfigurationClassParser {
* @param sourceClass a source class
* @return the superclass, or {@code null} if none found or previously processed
*/
@Nullable
protected final SourceClass doProcessConfigurationClass(
protected final @Nullable SourceClass doProcessConfigurationClass(
ConfigurationClass configClass, SourceClass sourceClass, Predicate<String> filter)
throws IOException {
@@ -707,8 +705,7 @@ class ConfigurationClassParser {
return allConditions.stream().filter(REGISTER_BEAN_CONDITION_FILTER).toList();
}
@Nullable
private ConfigurationClass getEnclosingConfigurationClass(ConfigurationClass configurationClass) {
private @Nullable ConfigurationClass getEnclosingConfigurationClass(ConfigurationClass configurationClass) {
String enclosingClassName = configurationClass.getMetadata().getEnclosingClassName();
if (enclosingClassName != null) {
return configurationClass.getImportedBy().stream()
@@ -729,8 +726,7 @@ class ConfigurationClassParser {
}
@Override
@Nullable
public AnnotationMetadata getImportingClassFor(String importedClass) {
public @Nullable AnnotationMetadata getImportingClassFor(String importedClass) {
return CollectionUtils.lastElement(this.imports.get(importedClass));
}
@@ -769,8 +765,7 @@ class ConfigurationClassParser {
private class DeferredImportSelectorHandler {
@Nullable
private List<DeferredImportSelectorHolder> deferredImportSelectors = new ArrayList<>();
private @Nullable List<DeferredImportSelectorHolder> deferredImportSelectors = new ArrayList<>();
/**
* Handle the specified {@link DeferredImportSelector}. If deferred import

View File

@@ -36,6 +36,7 @@ import javax.lang.model.element.Modifier;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.aop.framework.autoproxy.AutoProxyUtils;
import org.springframework.aot.generate.GeneratedMethod;
@@ -102,7 +103,6 @@ import org.springframework.javapoet.CodeBlock;
import org.springframework.javapoet.CodeBlock.Builder;
import org.springframework.javapoet.MethodSpec;
import org.springframework.javapoet.ParameterizedTypeName;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
@@ -152,13 +152,11 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
private ProblemReporter problemReporter = new FailFastProblemReporter();
@Nullable
private Environment environment;
private @Nullable Environment environment;
private ResourceLoader resourceLoader = new DefaultResourceLoader();
@Nullable
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
private MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory();
@@ -168,8 +166,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
private final Set<Integer> factoriesPostProcessed = new HashSet<>();
@Nullable
private ConfigurationClassBeanDefinitionReader reader;
private @Nullable ConfigurationClassBeanDefinitionReader reader;
private boolean localBeanNameGeneratorSet = false;
@@ -181,8 +178,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
private ApplicationStartup applicationStartup = ApplicationStartup.DEFAULT;
@Nullable
private List<PropertySourceDescriptor> propertySourceDescriptors;
private @Nullable List<PropertySourceDescriptor> propertySourceDescriptors;
@Override
@@ -311,9 +307,8 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
beanFactory.addBeanPostProcessor(new ImportAwareBeanPostProcessor(beanFactory));
}
@Nullable
@Override
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
Object configClassAttr = registeredBean.getMergedBeanDefinition()
.getAttribute(ConfigurationClassUtils.CONFIGURATION_CLASS_ATTRIBUTE);
if (ConfigurationClassUtils.CONFIGURATION_CLASS_FULL.equals(configClassAttr)) {
@@ -324,9 +319,8 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
}
@Override
@Nullable
@SuppressWarnings("NullAway")
public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) {
public @Nullable BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) {
boolean hasPropertySourceDescriptors = !CollectionUtils.isEmpty(this.propertySourceDescriptors);
boolean hasImportRegistry = beanFactory.containsBean(IMPORT_REGISTRY_BEAN_NAME);
if (hasPropertySourceDescriptors || hasImportRegistry) {
@@ -343,8 +337,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
return null;
}
@Nullable
private Resource resolvePropertySourceLocation(String location) {
private @Nullable Resource resolvePropertySourceLocation(String location) {
try {
String resolvedLocation = (this.environment != null ?
this.environment.resolveRequiredPlaceholders(location) : location);
@@ -557,8 +550,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
}
@Override
@Nullable
public PropertyValues postProcessProperties(@Nullable PropertyValues pvs, Object bean, String beanName) {
public @Nullable PropertyValues postProcessProperties(@Nullable PropertyValues pvs, Object bean, String beanName) {
// Inject the BeanFactory before AutowiredAnnotationBeanPostProcessor's
// postProcessProperties method attempts to autowire other configuration beans.
if (bean instanceof EnhancedConfiguration enhancedConfiguration) {

View File

@@ -22,6 +22,7 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.aop.framework.AopInfrastructureBean;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
@@ -38,7 +39,6 @@ import org.springframework.core.annotation.Order;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
/**
@@ -207,8 +207,7 @@ public abstract class ConfigurationClassUtils {
* or {@code Ordered.LOWEST_PRECEDENCE} if none declared
* @since 5.0
*/
@Nullable
public static Integer getOrder(AnnotationMetadata metadata) {
public static @Nullable Integer getOrder(AnnotationMetadata metadata) {
Map<String, Object> orderAttributes = metadata.getAnnotationAttributes(Order.class.getName());
return (orderAttributes != null ? ((Integer) orderAttributes.get(AnnotationUtils.VALUE)) : null);
}

View File

@@ -26,6 +26,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@@ -34,7 +36,6 @@ import org.springframework.beans.factory.config.DependencyDescriptor;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.MethodParameter;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.lang.Nullable;
/**
* Complete implementation of the
@@ -48,14 +49,12 @@ import org.springframework.lang.Nullable;
public class ContextAnnotationAutowireCandidateResolver extends QualifierAnnotationAutowireCandidateResolver {
@Override
@Nullable
public Object getLazyResolutionProxyIfNecessary(DependencyDescriptor descriptor, @Nullable String beanName) {
public @Nullable Object getLazyResolutionProxyIfNecessary(DependencyDescriptor descriptor, @Nullable String beanName) {
return (isLazy(descriptor) ? buildLazyResolutionProxy(descriptor, beanName) : null);
}
@Override
@Nullable
public Class<?> getLazyResolutionProxyClass(DependencyDescriptor descriptor, @Nullable String beanName) {
public @Nullable Class<?> getLazyResolutionProxyClass(DependencyDescriptor descriptor, @Nullable String beanName) {
return (isLazy(descriptor) ? (Class<?>) buildLazyResolutionProxy(descriptor, beanName, true) : null);
}
@@ -110,11 +109,9 @@ public class ContextAnnotationAutowireCandidateResolver extends QualifierAnnotat
private final DependencyDescriptor descriptor;
@Nullable
private final String beanName;
private final @Nullable String beanName;
@Nullable
private transient volatile Object cachedTarget;
private transient volatile @Nullable Object cachedTarget;
public LazyDependencyTargetSource(DefaultListableBeanFactory beanFactory,
DependencyDescriptor descriptor, @Nullable String beanName) {

View File

@@ -16,8 +16,9 @@
package org.springframework.context.annotation;
import org.jspecify.annotations.Nullable;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.lang.Nullable;
/**
* A variation of {@link ImportSelector} that runs after all {@code @Configuration} beans
@@ -43,8 +44,7 @@ public interface DeferredImportSelector extends ImportSelector {
* @return the import group class, or {@code null} if none
* @since 5.0
*/
@Nullable
default Class<? extends Group> getImportGroup() {
default @Nullable Class<? extends Group> getImportGroup() {
return null;
}

View File

@@ -19,13 +19,14 @@ package org.springframework.context.annotation;
import java.io.IOException;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.core.Ordered;
import org.springframework.core.PriorityOrdered;
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
/**
@@ -75,8 +76,7 @@ public final class ImportAwareAotBeanPostProcessor implements BeanPostProcessor,
}
}
@Nullable
private String getImportingClassFor(ImportAware instance) {
private @Nullable String getImportingClassFor(ImportAware instance) {
String target = ClassUtils.getUserClass(instance).getName();
return this.importsMapping.get(target);
}

View File

@@ -16,8 +16,9 @@
package org.springframework.context.annotation;
import org.jspecify.annotations.Nullable;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.lang.Nullable;
/**
* Registry of imported class {@link AnnotationMetadata}.
@@ -27,8 +28,7 @@ import org.springframework.lang.Nullable;
*/
interface ImportRegistry {
@Nullable
AnnotationMetadata getImportingClassFor(String importedClass);
@Nullable AnnotationMetadata getImportingClassFor(String importedClass);
void removeImportingClass(String importingClass);

View File

@@ -18,8 +18,9 @@ package org.springframework.context.annotation;
import java.util.function.Predicate;
import org.jspecify.annotations.Nullable;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.lang.Nullable;
/**
* Interface to be implemented by types that determine which @{@link Configuration}
@@ -77,8 +78,7 @@ public interface ImportSelector {
* of transitively imported configuration classes, or {@code null} if none
* @since 5.2.4
*/
@Nullable
default Predicate<String> getExclusionFilter() {
default @Nullable Predicate<String> getExclusionFilter() {
return null;
}

View File

@@ -20,9 +20,10 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.lang.Nullable;
/**
* Simple {@link ScopeMetadataResolver} implementation that follows JSR-330 scoping rules:
@@ -77,8 +78,7 @@ public class Jsr330ScopeMetadataResolver implements ScopeMetadataResolver {
* @param annotationType the JSR-330 annotation type
* @return the Spring scope name
*/
@Nullable
protected String resolveScopeName(String annotationType) {
protected @Nullable String resolveScopeName(String annotationType) {
return this.scopeMap.get(annotationType);
}

View File

@@ -16,6 +16,8 @@
package org.springframework.context.annotation;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -26,7 +28,6 @@ import org.springframework.context.weaving.DefaultContextLoadTimeWeaver;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.instrument.classloading.LoadTimeWeaver;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -45,14 +46,11 @@ import org.springframework.util.Assert;
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public class LoadTimeWeavingConfiguration implements ImportAware, BeanClassLoaderAware {
@Nullable
private AnnotationAttributes enableLTW;
private @Nullable AnnotationAttributes enableLTW;
@Nullable
private LoadTimeWeavingConfigurer ltwConfigurer;
private @Nullable LoadTimeWeavingConfigurer ltwConfigurer;
@Nullable
private ClassLoader beanClassLoader;
private @Nullable ClassLoader beanClassLoader;
@Override

View File

@@ -20,6 +20,8 @@ import java.util.Map;
import javax.management.MBeanServer;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -29,7 +31,6 @@ import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.jmx.export.annotation.AnnotationMBeanExporter;
import org.springframework.jmx.support.RegistrationPolicy;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -50,14 +51,11 @@ public class MBeanExportConfiguration implements ImportAware, EnvironmentAware,
private static final String MBEAN_EXPORTER_BEAN_NAME = "mbeanExporter";
@Nullable
private AnnotationAttributes enableMBeanExport;
private @Nullable AnnotationAttributes enableMBeanExport;
@Nullable
private Environment environment;
private @Nullable Environment environment;
@Nullable
private BeanFactory beanFactory;
private @Nullable BeanFactory beanFactory;
@Override

View File

@@ -18,6 +18,8 @@ package org.springframework.context.annotation;
import java.lang.reflect.Constructor;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanInstantiationException;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.Aware;
@@ -30,7 +32,6 @@ import org.springframework.context.EnvironmentAware;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -98,8 +99,7 @@ abstract class ParserStrategyUtils {
return parameters;
}
@Nullable
private static Object resolveParameter(Class<?> parameterType,
private static @Nullable Object resolveParameter(Class<?> parameterType,
Environment environment, ResourceLoader resourceLoader,
BeanDefinitionRegistry registry, @Nullable ClassLoader classLoader) {

View File

@@ -23,6 +23,8 @@ import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
@@ -30,7 +32,6 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.DependencyDescriptor;
import org.springframework.beans.factory.support.RegisteredBean;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
@@ -115,9 +116,8 @@ public abstract class ResourceElementResolver {
* @param registeredBean the registered bean
* @return the resolved field or method parameter value
*/
@Nullable
@SuppressWarnings("unchecked")
public <T> T resolve(RegisteredBean registeredBean) {
public <T> @Nullable T resolve(RegisteredBean registeredBean) {
Assert.notNull(registeredBean, "'registeredBean' must not be null");
return (T) (isLazyLookup(registeredBean) ? buildLazyResourceProxy(registeredBean) :
resolveValue(registeredBean));

View File

@@ -16,13 +16,14 @@
package org.springframework.context.annotation;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.MethodMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -70,8 +71,7 @@ public class ScannedGenericBeanDefinition extends GenericBeanDefinition implemen
}
@Override
@Nullable
public MethodMetadata getFactoryMethodMetadata() {
public @Nullable MethodMetadata getFactoryMethodMetadata() {
return null;
}

View File

@@ -3,9 +3,7 @@
* annotations, component-scanning, and Java-based metadata for creating
* Spring-managed objects.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.context.annotation;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -19,11 +19,12 @@ package org.springframework.context.aot;
import java.io.IOException;
import java.nio.file.Path;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.generate.FileSystemGeneratedFiles;
import org.springframework.aot.generate.GeneratedFiles.Kind;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.nativex.FileNativeConfigurationWriter;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.FileSystemUtils;
@@ -197,20 +198,15 @@ public abstract class AbstractAotProcessor<T> {
*/
public static final class Builder {
@Nullable
private Path sourceOutput;
private @Nullable Path sourceOutput;
@Nullable
private Path resourceOutput;
private @Nullable Path resourceOutput;
@Nullable
private Path classOutput;
private @Nullable Path classOutput;
@Nullable
private String groupId;
private @Nullable String groupId;
@Nullable
private String artifactId;
private @Nullable String artifactId;
private Builder() {
// internal constructor

View File

@@ -18,13 +18,13 @@ package org.springframework.context.aot;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanInstantiationException;
import org.springframework.beans.BeanUtils;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.log.LogMessage;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;

View File

@@ -23,6 +23,8 @@ import java.util.function.Function;
import javax.lang.model.element.Modifier;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.generate.GeneratedClass;
import org.springframework.aot.generate.GeneratedMethods;
import org.springframework.aot.generate.GenerationContext;
@@ -44,7 +46,6 @@ import org.springframework.javapoet.MethodSpec;
import org.springframework.javapoet.ParameterizedTypeName;
import org.springframework.javapoet.TypeName;
import org.springframework.javapoet.TypeSpec;
import org.springframework.lang.Nullable;
/**
* Internal code generator to create the {@link ApplicationContextInitializer}.
@@ -142,13 +143,11 @@ class ApplicationContextInitializationCodeGenerator implements BeanFactoryInitia
private static class InitializerMethodArgumentCodeGenerator implements Function<TypeName, CodeBlock> {
@Override
@Nullable
public CodeBlock apply(TypeName typeName) {
public @Nullable CodeBlock apply(TypeName typeName) {
return (typeName instanceof ClassName className ? apply(className) : null);
}
@Nullable
private CodeBlock apply(ClassName className) {
private @Nullable CodeBlock apply(ClassName className) {
String name = className.canonicalName();
if (name.equals(DefaultListableBeanFactory.class.getName())
|| name.equals(ConfigurableListableBeanFactory.class.getName())) {

View File

@@ -20,6 +20,8 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.generate.GenerationContext;
import org.springframework.beans.factory.aot.AotException;
import org.springframework.beans.factory.aot.AotProcessingException;
@@ -28,7 +30,6 @@ import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContrib
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor;
import org.springframework.beans.factory.aot.BeanFactoryInitializationCode;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.lang.Nullable;
/**
* A collection of {@link BeanFactoryInitializationAotContribution AOT
@@ -74,8 +75,7 @@ class BeanFactoryInitializationAotContributions {
return Collections.unmodifiableList(contributions);
}
@Nullable
private BeanFactoryInitializationAotContribution processAheadOfTime(BeanFactoryInitializationAotProcessor processor,
private @Nullable BeanFactoryInitializationAotContribution processAheadOfTime(BeanFactoryInitializationAotProcessor processor,
DefaultListableBeanFactory beanFactory) {
try {

View File

@@ -16,6 +16,8 @@
package org.springframework.context.aot;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.generate.GenerationContext;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.beans.factory.aot.BeanRegistrationAotContribution;
@@ -23,7 +25,6 @@ import org.springframework.beans.factory.aot.BeanRegistrationAotProcessor;
import org.springframework.beans.factory.aot.BeanRegistrationCode;
import org.springframework.beans.factory.support.RegisteredBean;
import org.springframework.core.KotlinDetector;
import org.springframework.lang.Nullable;
/**
* AOT {@code BeanRegistrationAotProcessor} that adds additional hints
@@ -35,8 +36,7 @@ import org.springframework.lang.Nullable;
class KotlinReflectionBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor {
@Override
@Nullable
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
Class<?> beanClass = registeredBean.getBeanClass();
if (KotlinDetector.isKotlinType(beanClass)) {
return new AotContribution(beanClass);

View File

@@ -22,6 +22,8 @@ import java.util.LinkedHashSet;
import java.util.Set;
import java.util.stream.StreamSupport;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.generate.GenerationContext;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.annotation.Reflective;
@@ -33,7 +35,6 @@ import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContrib
import org.springframework.beans.factory.aot.BeanFactoryInitializationCode;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
/**
@@ -95,8 +96,7 @@ public class ReflectiveProcessorAotContributionBuilder {
return withClasses(scanner.scan(packageNames));
}
@Nullable
public BeanFactoryInitializationAotContribution build() {
public @Nullable BeanFactoryInitializationAotContribution build() {
return (!this.classes.isEmpty() ? new AotContribution(this.classes) : null);
}
@@ -118,8 +118,7 @@ public class ReflectiveProcessorAotContributionBuilder {
private static class ReflectiveClassPathScanner extends ClassPathScanningCandidateComponentProvider {
@Nullable
private final ClassLoader classLoader;
private final @Nullable ClassLoader classLoader;
ReflectiveClassPathScanner(@Nullable ClassLoader classLoader) {
super(false);

View File

@@ -21,6 +21,8 @@ import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.hint.annotation.Reflective;
import org.springframework.aot.hint.annotation.ReflectiveProcessor;
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContribution;
@@ -29,7 +31,6 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.RegisteredBean;
import org.springframework.context.annotation.ReflectiveScan;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
/**
@@ -43,8 +44,7 @@ import org.springframework.util.ClassUtils;
class ReflectiveProcessorBeanFactoryInitializationAotProcessor implements BeanFactoryInitializationAotProcessor {
@Override
@Nullable
public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) {
public @Nullable BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) {
Class<?>[] beanClasses = Arrays.stream(beanFactory.getBeanDefinitionNames())
.map(beanName -> RegisteredBean.of(beanFactory, beanName).getBeanClass())
.toArray(Class<?>[]::new);

View File

@@ -23,6 +23,7 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.generate.GenerationContext;
import org.springframework.aot.hint.RuntimeHints;
@@ -35,7 +36,6 @@ import org.springframework.beans.factory.aot.BeanFactoryInitializationCode;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.ImportRuntimeHints;
import org.springframework.core.log.LogMessage;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
/**
@@ -94,8 +94,7 @@ class RuntimeHintsBeanFactoryInitializationAotProcessor implements BeanFactoryIn
private final Iterable<RuntimeHintsRegistrar> registrars;
@Nullable
private final ClassLoader beanClassLoader;
private final @Nullable ClassLoader beanClassLoader;
RuntimeHintsRegistrarContribution(Iterable<RuntimeHintsRegistrar> registrars,
@Nullable ClassLoader beanClassLoader) {

View File

@@ -1,9 +1,7 @@
/**
* AOT support for application contexts.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.context.aot;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -16,6 +16,7 @@
package org.springframework.context.config;
import org.jspecify.annotations.Nullable;
import org.w3c.dom.Element;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -27,7 +28,6 @@ import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.weaving.AspectJWeavingEnabler;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
/**

View File

@@ -16,6 +16,7 @@
package org.springframework.context.config;
import org.jspecify.annotations.Nullable;
import org.w3c.dom.Element;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -23,7 +24,6 @@ import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.lang.Nullable;
/**
* {@link BeanDefinitionParser} responsible for parsing the
@@ -45,8 +45,7 @@ class SpringConfiguredBeanDefinitionParser implements BeanDefinitionParser {
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
public @Nullable BeanDefinition parse(Element element, ParserContext parserContext) {
if (!parserContext.getRegistry().containsBeanDefinition(BEAN_CONFIGURER_ASPECT_BEAN_NAME)) {
RootBeanDefinition def = new RootBeanDefinition();
def.setBeanClassName(BEAN_CONFIGURER_ASPECT_CLASS_NAME);

Some files were not shown because too many files have changed in this diff Show More