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

@@ -33,13 +33,13 @@ import java.util.Optional;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.core.CollectionFactory;
import org.springframework.core.ResolvableType;
import org.springframework.core.convert.ConversionException;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@@ -78,17 +78,14 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
private int autoGrowCollectionLimit = Integer.MAX_VALUE;
@Nullable
Object wrappedObject;
@Nullable Object wrappedObject;
private String nestedPath = "";
@Nullable
Object rootObject;
@Nullable Object rootObject;
/** Map with cached nested Accessors: nested path -> Accessor instance. */
@Nullable
private Map<String, AbstractNestablePropertyAccessor> nestedPropertyAccessors;
private @Nullable Map<String, AbstractNestablePropertyAccessor> nestedPropertyAccessors;
/**
@@ -488,8 +485,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
}
@Override
@Nullable
public Class<?> getPropertyType(String propertyName) throws BeansException {
public @Nullable Class<?> getPropertyType(String propertyName) throws BeansException {
try {
PropertyHandler ph = getPropertyHandler(propertyName);
if (ph != null) {
@@ -516,8 +512,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
}
@Override
@Nullable
public TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException {
public @Nullable TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException {
try {
AbstractNestablePropertyAccessor nestedPa = getPropertyAccessorForPropertyPath(propertyName);
String finalPath = getFinalPath(nestedPa, propertyName);
@@ -580,8 +575,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
return false;
}
@Nullable
private Object convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue,
private @Nullable Object convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue,
@Nullable Object newValue, @Nullable Class<?> requiredType, @Nullable TypeDescriptor td)
throws TypeMismatchException {
@@ -601,8 +595,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
}
}
@Nullable
protected Object convertForProperty(
protected @Nullable Object convertForProperty(
String propertyName, @Nullable Object oldValue, @Nullable Object newValue, TypeDescriptor td)
throws TypeMismatchException {
@@ -610,16 +603,14 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
}
@Override
@Nullable
public Object getPropertyValue(String propertyName) throws BeansException {
public @Nullable Object getPropertyValue(String propertyName) throws BeansException {
AbstractNestablePropertyAccessor nestedPa = getPropertyAccessorForPropertyPath(propertyName);
PropertyTokenHolder tokens = getPropertyNameTokens(getFinalPath(nestedPa, propertyName));
return nestedPa.getPropertyValue(tokens);
}
@SuppressWarnings({"rawtypes", "unchecked"})
@Nullable
protected Object getPropertyValue(PropertyTokenHolder tokens) throws BeansException {
protected @Nullable Object getPropertyValue(PropertyTokenHolder tokens) throws BeansException {
String propertyName = tokens.canonicalName;
String actualName = tokens.actualName;
PropertyHandler ph = getLocalPropertyHandler(actualName);
@@ -734,8 +725,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
* or {@code null} if not found
* @throws BeansException in case of introspection failure
*/
@Nullable
protected PropertyHandler getPropertyHandler(String propertyName) throws BeansException {
protected @Nullable PropertyHandler getPropertyHandler(String propertyName) throws BeansException {
Assert.notNull(propertyName, "Property name must not be null");
AbstractNestablePropertyAccessor nestedPa = getPropertyAccessorForPropertyPath(propertyName);
return nestedPa.getLocalPropertyHandler(getFinalPath(nestedPa, propertyName));
@@ -747,8 +737,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
* @param propertyName the name of a local property
* @return the handler for that property, or {@code null} if it has not been found
*/
@Nullable
protected abstract PropertyHandler getLocalPropertyHandler(String propertyName);
protected abstract @Nullable PropertyHandler getLocalPropertyHandler(String propertyName);
/**
* Create a new nested property accessor instance.
@@ -1016,8 +1005,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
*/
protected abstract static class PropertyHandler {
@Nullable
private final Class<?> propertyType;
private final @Nullable Class<?> propertyType;
private final boolean readable;
@@ -1029,8 +1017,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
this.writable = writable;
}
@Nullable
public Class<?> getPropertyType() {
public @Nullable Class<?> getPropertyType() {
return this.propertyType;
}
@@ -1058,11 +1045,9 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
return TypeDescriptor.valueOf(getResolvableType().getNested(nestingLevel).asCollection().resolveGeneric());
}
@Nullable
public abstract TypeDescriptor nested(int level);
public abstract @Nullable TypeDescriptor nested(int level);
@Nullable
public abstract Object getValue() throws Exception;
public abstract @Nullable Object getValue() throws Exception;
public abstract void setValue(@Nullable Object value) throws Exception;
@@ -1086,8 +1071,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
public String canonicalName;
@Nullable
public String[] keys;
public String @Nullable [] keys;
}
}

View File

@@ -21,7 +21,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Abstract implementation of the {@link PropertyAccessor} interface.
@@ -139,8 +139,7 @@ public abstract class AbstractPropertyAccessor extends TypeConverterSupport impl
// Redefined with public visibility.
@Override
@Nullable
public Class<?> getPropertyType(String propertyPath) {
public @Nullable Class<?> getPropertyType(String propertyPath) {
return null;
}
@@ -154,8 +153,7 @@ public abstract class AbstractPropertyAccessor extends TypeConverterSupport impl
* accessor method failed
*/
@Override
@Nullable
public abstract Object getPropertyValue(String propertyName) throws BeansException;
public abstract @Nullable Object getPropertyValue(String propertyName) throws BeansException;
/**
* Actually set a property value.

View File

@@ -19,7 +19,7 @@ package org.springframework.beans;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Strategy interface for creating {@link BeanInfo} instances for Spring beans.
@@ -54,7 +54,6 @@ public interface BeanInfoFactory {
* @return the BeanInfo, or {@code null} if the given class is not supported
* @throws IntrospectionException in case of exceptions
*/
@Nullable
BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException;
@Nullable BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException;
}

View File

@@ -19,7 +19,7 @@ package org.springframework.beans;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Exception thrown when instantiation of a bean failed.
@@ -33,11 +33,9 @@ public class BeanInstantiationException extends FatalBeanException {
private final Class<?> beanClass;
@Nullable
private final Constructor<?> constructor;
private final @Nullable Constructor<?> constructor;
@Nullable
private final Method constructingMethod;
private final @Nullable Method constructingMethod;
/**
@@ -106,8 +104,7 @@ public class BeanInstantiationException extends FatalBeanException {
* factory method or in case of default instantiation
* @since 4.3
*/
@Nullable
public Constructor<?> getConstructor() {
public @Nullable Constructor<?> getConstructor() {
return this.constructor;
}
@@ -117,8 +114,7 @@ public class BeanInstantiationException extends FatalBeanException {
* or {@code null} in case of constructor-based instantiation
* @since 4.3
*/
@Nullable
public Method getConstructingMethod() {
public @Nullable Method getConstructingMethod() {
return this.constructingMethod;
}

View File

@@ -16,7 +16,8 @@
package org.springframework.beans;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -32,11 +33,9 @@ public class BeanMetadataAttribute implements BeanMetadataElement {
private final String name;
@Nullable
private final Object value;
private final @Nullable Object value;
@Nullable
private Object source;
private @Nullable Object source;
/**
@@ -61,8 +60,7 @@ public class BeanMetadataAttribute implements BeanMetadataElement {
/**
* Return the value of the attribute.
*/
@Nullable
public Object getValue() {
public @Nullable Object getValue() {
return this.value;
}
@@ -75,8 +73,7 @@ public class BeanMetadataAttribute implements BeanMetadataElement {
}
@Override
@Nullable
public Object getSource() {
public @Nullable Object getSource() {
return this.source;
}

View File

@@ -16,8 +16,9 @@
package org.springframework.beans;
import org.jspecify.annotations.Nullable;
import org.springframework.core.AttributeAccessorSupport;
import org.springframework.lang.Nullable;
/**
* Extension of {@link org.springframework.core.AttributeAccessorSupport},
@@ -30,8 +31,7 @@ import org.springframework.lang.Nullable;
@SuppressWarnings("serial")
public class BeanMetadataAttributeAccessor extends AttributeAccessorSupport implements BeanMetadataElement {
@Nullable
private Object source;
private @Nullable Object source;
/**
@@ -43,8 +43,7 @@ public class BeanMetadataAttributeAccessor extends AttributeAccessorSupport impl
}
@Override
@Nullable
public Object getSource() {
public @Nullable Object getSource() {
return this.source;
}
@@ -63,8 +62,7 @@ public class BeanMetadataAttributeAccessor extends AttributeAccessorSupport impl
* @return the corresponding BeanMetadataAttribute object,
* or {@code null} if no such attribute defined
*/
@Nullable
public BeanMetadataAttribute getMetadataAttribute(String name) {
public @Nullable BeanMetadataAttribute getMetadataAttribute(String name) {
return (BeanMetadataAttribute) super.getAttribute(name);
}
@@ -74,15 +72,13 @@ public class BeanMetadataAttributeAccessor extends AttributeAccessorSupport impl
}
@Override
@Nullable
public Object getAttribute(String name) {
public @Nullable Object getAttribute(String name) {
BeanMetadataAttribute attribute = (BeanMetadataAttribute) super.getAttribute(name);
return (attribute != null ? attribute.getValue() : null);
}
@Override
@Nullable
public Object removeAttribute(String name) {
public @Nullable Object removeAttribute(String name) {
BeanMetadataAttribute attribute = (BeanMetadataAttribute) super.removeAttribute(name);
return (attribute != null ? attribute.getValue() : null);
}

View File

@@ -16,7 +16,7 @@
package org.springframework.beans;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Interface to be implemented by bean metadata elements
@@ -31,8 +31,7 @@ public interface BeanMetadataElement {
* Return the configuration source {@code Object} for this metadata element
* (may be {@code null}).
*/
@Nullable
default Object getSource() {
default @Nullable Object getSource() {
return null;
}

View File

@@ -39,13 +39,13 @@ import kotlin.reflect.KParameter;
import kotlin.reflect.full.KClasses;
import kotlin.reflect.jvm.KCallablesJvm;
import kotlin.reflect.jvm.ReflectJvmMapping;
import org.jspecify.annotations.Nullable;
import org.springframework.core.DefaultParameterNameDiscoverer;
import org.springframework.core.KotlinDetector;
import org.springframework.core.MethodParameter;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
@@ -182,7 +182,7 @@ public abstract class BeanUtils {
* @throws BeanInstantiationException if the bean cannot be instantiated
* @see Constructor#newInstance
*/
public static <T> T instantiateClass(Constructor<T> ctor, Object... args) throws BeanInstantiationException {
public static <T> T instantiateClass(Constructor<T> ctor, @Nullable Object... args) throws BeanInstantiationException {
Assert.notNull(ctor, "Constructor must not be null");
try {
ReflectionUtils.makeAccessible(ctor);
@@ -277,8 +277,7 @@ public abstract class BeanUtils {
* @see <a href="https://kotlinlang.org/docs/reference/classes.html#constructors">Kotlin constructors</a>
* @see <a href="https://docs.oracle.com/javase/specs/jls/se17/html/jls-8.html#jls-8.10.4">Record constructor declarations</a>
*/
@Nullable
public static <T> Constructor<T> findPrimaryConstructor(Class<T> clazz) {
public static <T> @Nullable Constructor<T> findPrimaryConstructor(Class<T> clazz) {
Assert.notNull(clazz, "Class must not be null");
if (KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(clazz)) {
return KotlinDelegate.findPrimaryConstructor(clazz);
@@ -313,8 +312,7 @@ public abstract class BeanUtils {
* @see Class#getMethod
* @see #findDeclaredMethod
*/
@Nullable
public static Method findMethod(Class<?> clazz, String methodName, Class<?>... paramTypes) {
public static @Nullable Method findMethod(Class<?> clazz, String methodName, Class<?>... paramTypes) {
try {
return clazz.getMethod(methodName, paramTypes);
}
@@ -334,8 +332,7 @@ public abstract class BeanUtils {
* @return the Method object, or {@code null} if not found
* @see Class#getDeclaredMethod
*/
@Nullable
public static Method findDeclaredMethod(Class<?> clazz, String methodName, Class<?>... paramTypes) {
public static @Nullable Method findDeclaredMethod(Class<?> clazz, String methodName, Class<?>... paramTypes) {
try {
return clazz.getDeclaredMethod(methodName, paramTypes);
}
@@ -362,8 +359,7 @@ public abstract class BeanUtils {
* @see Class#getMethods
* @see #findDeclaredMethodWithMinimalParameters
*/
@Nullable
public static Method findMethodWithMinimalParameters(Class<?> clazz, String methodName)
public static @Nullable Method findMethodWithMinimalParameters(Class<?> clazz, String methodName)
throws IllegalArgumentException {
Method targetMethod = findMethodWithMinimalParameters(clazz.getMethods(), methodName);
@@ -385,8 +381,7 @@ public abstract class BeanUtils {
* could not be resolved to a unique method with minimal parameters
* @see Class#getDeclaredMethods
*/
@Nullable
public static Method findDeclaredMethodWithMinimalParameters(Class<?> clazz, String methodName)
public static @Nullable Method findDeclaredMethodWithMinimalParameters(Class<?> clazz, String methodName)
throws IllegalArgumentException {
Method targetMethod = findMethodWithMinimalParameters(clazz.getDeclaredMethods(), methodName);
@@ -405,8 +400,7 @@ public abstract class BeanUtils {
* @throws IllegalArgumentException if methods of the given name were found but
* could not be resolved to a unique method with minimal parameters
*/
@Nullable
public static Method findMethodWithMinimalParameters(Method[] methods, String methodName)
public static @Nullable Method findMethodWithMinimalParameters(Method[] methods, String methodName)
throws IllegalArgumentException {
Method targetMethod = null;
@@ -457,8 +451,7 @@ public abstract class BeanUtils {
* @see #findMethod
* @see #findMethodWithMinimalParameters
*/
@Nullable
public static Method resolveSignature(String signature, Class<?> clazz) {
public static @Nullable Method resolveSignature(String signature, Class<?> clazz) {
Assert.hasText(signature, "'signature' must not be empty");
Assert.notNull(clazz, "Class must not be null");
int startParen = signature.indexOf('(');
@@ -511,8 +504,7 @@ public abstract class BeanUtils {
* @return the corresponding PropertyDescriptor, or {@code null} if none
* @throws BeansException if PropertyDescriptor lookup fails
*/
@Nullable
public static PropertyDescriptor getPropertyDescriptor(Class<?> clazz, String propertyName) throws BeansException {
public static @Nullable PropertyDescriptor getPropertyDescriptor(Class<?> clazz, String propertyName) throws BeansException {
return CachedIntrospectionResults.forClass(clazz).getPropertyDescriptor(propertyName);
}
@@ -525,8 +517,7 @@ public abstract class BeanUtils {
* @return the corresponding PropertyDescriptor, or {@code null} if none
* @throws BeansException if PropertyDescriptor lookup fails
*/
@Nullable
public static PropertyDescriptor findPropertyForMethod(Method method) throws BeansException {
public static @Nullable PropertyDescriptor findPropertyForMethod(Method method) throws BeansException {
return findPropertyForMethod(method, method.getDeclaringClass());
}
@@ -540,8 +531,7 @@ public abstract class BeanUtils {
* @throws BeansException if PropertyDescriptor lookup fails
* @since 3.2.13
*/
@Nullable
public static PropertyDescriptor findPropertyForMethod(Method method, Class<?> clazz) throws BeansException {
public static @Nullable PropertyDescriptor findPropertyForMethod(Method method, Class<?> clazz) throws BeansException {
Assert.notNull(method, "Method must not be null");
PropertyDescriptor[] pds = getPropertyDescriptors(clazz);
for (PropertyDescriptor pd : pds) {
@@ -561,8 +551,7 @@ public abstract class BeanUtils {
* @param targetType the type to find an editor for
* @return the corresponding editor, or {@code null} if none found
*/
@Nullable
public static PropertyEditor findEditorByConvention(@Nullable Class<?> targetType) {
public static @Nullable PropertyEditor findEditorByConvention(@Nullable Class<?> targetType) {
if (targetType == null || targetType.isArray() || unknownEditorTypes.contains(targetType)) {
return null;
}
@@ -609,7 +598,7 @@ public abstract class BeanUtils {
* @param beanClasses the classes to check against
* @return the property type, or {@code Object.class} as fallback
*/
public static Class<?> findPropertyType(String propertyName, @Nullable Class<?>... beanClasses) {
public static Class<?> findPropertyType(String propertyName, Class<?> @Nullable ... beanClasses) {
if (beanClasses != null) {
for (Class<?> beanClass : beanClasses) {
PropertyDescriptor pd = getPropertyDescriptor(beanClass, propertyName);
@@ -803,7 +792,7 @@ public abstract class BeanUtils {
* @see BeanWrapper
*/
private static void copyProperties(Object source, Object target, @Nullable Class<?> editable,
@Nullable String... ignoreProperties) throws BeansException {
String @Nullable ... ignoreProperties) throws BeansException {
Assert.notNull(source, "Source must not be null");
Assert.notNull(target, "Target must not be null");
@@ -880,8 +869,7 @@ public abstract class BeanUtils {
* https://kotlinlang.org/docs/reference/classes.html#constructors</a>
*/
@SuppressWarnings("unchecked")
@Nullable
public static <T> Constructor<T> findPrimaryConstructor(Class<T> clazz) {
public static <T> @Nullable Constructor<T> findPrimaryConstructor(Class<T> clazz) {
try {
KClass<T> kClass = JvmClassMappingKt.getKotlinClass(clazz);
KFunction<T> primaryCtor = KClasses.getPrimaryConstructor(kClass);
@@ -912,7 +900,7 @@ public abstract class BeanUtils {
* @param args the constructor arguments to apply
* (use {@code null} for unspecified parameter if needed)
*/
public static <T> T instantiateClass(Constructor<T> ctor, Object... args)
public static <T> T instantiateClass(Constructor<T> ctor, @Nullable Object... args)
throws IllegalAccessException, InvocationTargetException, InstantiationException {
KFunction<T> kotlinConstructor = ReflectJvmMapping.getKotlinFunction(ctor);

View File

@@ -16,12 +16,13 @@
package org.springframework.beans;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.ReflectionHints;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.core.io.ResourceEditor;
import org.springframework.lang.Nullable;
/**
* {@link RuntimeHintsRegistrar} to register hints for popular conventions in

View File

@@ -20,11 +20,11 @@ import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.core.MethodParameter;
import org.springframework.core.ResolvableType;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
@@ -64,8 +64,7 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
* Cached introspections results for this object, to prevent encountering
* the cost of JavaBeans introspection every time.
*/
@Nullable
private CachedIntrospectionResults cachedIntrospectionResults;
private @Nullable CachedIntrospectionResults cachedIntrospectionResults;
/**
@@ -178,8 +177,7 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
* @return the new value, possibly the result of type conversion
* @throws TypeMismatchException if type conversion failed
*/
@Nullable
public Object convertForProperty(@Nullable Object value, String propertyName) throws TypeMismatchException {
public @Nullable Object convertForProperty(@Nullable Object value, String propertyName) throws TypeMismatchException {
CachedIntrospectionResults cachedIntrospectionResults = getCachedIntrospectionResults();
PropertyDescriptor pd = cachedIntrospectionResults.getPropertyDescriptor(propertyName);
if (pd == null) {
@@ -191,8 +189,7 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
}
@Override
@Nullable
protected BeanPropertyHandler getLocalPropertyHandler(String propertyName) {
protected @Nullable BeanPropertyHandler getLocalPropertyHandler(String propertyName) {
PropertyDescriptor pd = getCachedIntrospectionResults().getPropertyDescriptor(propertyName);
return (pd != null ? new BeanPropertyHandler((GenericTypeAwarePropertyDescriptor) pd) : null);
}
@@ -261,14 +258,12 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements
}
@Override
@Nullable
public TypeDescriptor nested(int level) {
public @Nullable TypeDescriptor nested(int level) {
return this.pd.getTypeDescriptor().nested(level);
}
@Override
@Nullable
public Object getValue() throws Exception {
public @Nullable Object getValue() throws Exception {
Method readMethod = this.pd.getReadMethod();
Assert.state(readMethod != null, "No read method available");
ReflectionUtils.makeAccessible(readMethod);

View File

@@ -16,8 +16,9 @@
package org.springframework.beans;
import org.jspecify.annotations.Nullable;
import org.springframework.core.NestedRuntimeException;
import org.springframework.lang.Nullable;
/**
* Abstract superclass for all exceptions thrown in the beans package

View File

@@ -33,9 +33,9 @@ import java.util.concurrent.ConcurrentMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.ConcurrentReferenceHashMap;
import org.springframework.util.StringUtils;
@@ -375,8 +375,7 @@ public final class CachedIntrospectionResults {
return this.beanInfo.getBeanDescriptor().getBeanClass();
}
@Nullable
PropertyDescriptor getPropertyDescriptor(String name) {
@Nullable PropertyDescriptor getPropertyDescriptor(String name) {
PropertyDescriptor pd = this.propertyDescriptors.get(name);
if (pd == null && StringUtils.hasLength(name)) {
// Same lenient fallback checking as in Property...

View File

@@ -16,8 +16,9 @@
package org.springframework.beans;
import org.jspecify.annotations.Nullable;
import org.springframework.core.convert.ConversionService;
import org.springframework.lang.Nullable;
/**
* Interface that encapsulates configuration methods for a PropertyAccessor.
@@ -42,8 +43,7 @@ public interface ConfigurablePropertyAccessor extends PropertyAccessor, Property
/**
* Return the associated ConversionService, if any.
*/
@Nullable
ConversionService getConversionService();
@Nullable ConversionService getConversionService();
/**
* Set whether to extract the old property value when applying a

View File

@@ -18,7 +18,7 @@ package org.springframework.beans;
import java.beans.PropertyChangeEvent;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Exception thrown when no suitable editor or converter can be found for a bean property.

View File

@@ -20,9 +20,10 @@ import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.springframework.core.ResolvableType;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.lang.Nullable;
import org.springframework.util.ReflectionUtils;
/**
@@ -71,8 +72,7 @@ public class DirectFieldAccessor extends AbstractNestablePropertyAccessor {
@Override
@Nullable
protected FieldPropertyHandler getLocalPropertyHandler(String propertyName) {
protected @Nullable FieldPropertyHandler getLocalPropertyHandler(String propertyName) {
FieldPropertyHandler propertyHandler = this.fieldMap.get(propertyName);
if (propertyHandler == null) {
Field field = ReflectionUtils.findField(getWrappedClass(), propertyName);
@@ -132,14 +132,12 @@ public class DirectFieldAccessor extends AbstractNestablePropertyAccessor {
}
@Override
@Nullable
public TypeDescriptor nested(int level) {
public @Nullable TypeDescriptor nested(int level) {
return TypeDescriptor.nested(this.field, level);
}
@Override
@Nullable
public Object getValue() throws Exception {
public @Nullable Object getValue() throws Exception {
try {
ReflectionUtils.makeAccessible(this.field);
return this.field.get(getWrappedInstance());

View File

@@ -36,8 +36,8 @@ import java.util.TreeSet;
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;
/**
@@ -185,8 +185,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
}
@Nullable
private PropertyDescriptor findExistingPropertyDescriptor(String propertyName, Class<?> propertyType) {
private @Nullable PropertyDescriptor findExistingPropertyDescriptor(String propertyName, Class<?> propertyType) {
for (PropertyDescriptor pd : this.propertyDescriptors) {
final Class<?> candidateType;
final String candidateName = pd.getName();
@@ -265,17 +264,13 @@ class ExtendedBeanInfo implements BeanInfo {
*/
static class SimplePropertyDescriptor extends PropertyDescriptor {
@Nullable
private Method readMethod;
private @Nullable Method readMethod;
@Nullable
private Method writeMethod;
private @Nullable Method writeMethod;
@Nullable
private Class<?> propertyType;
private @Nullable Class<?> propertyType;
@Nullable
private Class<?> propertyEditorClass;
private @Nullable Class<?> propertyEditorClass;
public SimplePropertyDescriptor(PropertyDescriptor original) throws IntrospectionException {
this(original.getName(), original.getReadMethod(), original.getWriteMethod());
@@ -292,8 +287,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
@Nullable
public Method getReadMethod() {
public @Nullable Method getReadMethod() {
return this.readMethod;
}
@@ -303,8 +297,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
@Nullable
public Method getWriteMethod() {
public @Nullable Method getWriteMethod() {
return this.writeMethod;
}
@@ -314,8 +307,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
@Nullable
public Class<?> getPropertyType() {
public @Nullable Class<?> getPropertyType() {
if (this.propertyType == null) {
try {
this.propertyType = PropertyDescriptorUtils.findPropertyType(this.readMethod, this.writeMethod);
@@ -328,8 +320,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
@Nullable
public Class<?> getPropertyEditorClass() {
public @Nullable Class<?> getPropertyEditorClass() {
return this.propertyEditorClass;
}
@@ -362,26 +353,19 @@ class ExtendedBeanInfo implements BeanInfo {
*/
static class SimpleIndexedPropertyDescriptor extends IndexedPropertyDescriptor {
@Nullable
private Method readMethod;
private @Nullable Method readMethod;
@Nullable
private Method writeMethod;
private @Nullable Method writeMethod;
@Nullable
private Class<?> propertyType;
private @Nullable Class<?> propertyType;
@Nullable
private Method indexedReadMethod;
private @Nullable Method indexedReadMethod;
@Nullable
private Method indexedWriteMethod;
private @Nullable Method indexedWriteMethod;
@Nullable
private Class<?> indexedPropertyType;
private @Nullable Class<?> indexedPropertyType;
@Nullable
private Class<?> propertyEditorClass;
private @Nullable Class<?> propertyEditorClass;
public SimpleIndexedPropertyDescriptor(IndexedPropertyDescriptor original) throws IntrospectionException {
this(original.getName(), original.getReadMethod(), original.getWriteMethod(),
@@ -404,8 +388,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
@Nullable
public Method getReadMethod() {
public @Nullable Method getReadMethod() {
return this.readMethod;
}
@@ -415,8 +398,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
@Nullable
public Method getWriteMethod() {
public @Nullable Method getWriteMethod() {
return this.writeMethod;
}
@@ -426,8 +408,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
@Nullable
public Class<?> getPropertyType() {
public @Nullable Class<?> getPropertyType() {
if (this.propertyType == null) {
try {
this.propertyType = PropertyDescriptorUtils.findPropertyType(this.readMethod, this.writeMethod);
@@ -440,8 +421,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
@Nullable
public Method getIndexedReadMethod() {
public @Nullable Method getIndexedReadMethod() {
return this.indexedReadMethod;
}
@@ -451,8 +431,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
@Nullable
public Method getIndexedWriteMethod() {
public @Nullable Method getIndexedWriteMethod() {
return this.indexedWriteMethod;
}
@@ -462,8 +441,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
@Nullable
public Class<?> getIndexedPropertyType() {
public @Nullable Class<?> getIndexedPropertyType() {
if (this.indexedPropertyType == null) {
try {
this.indexedPropertyType = PropertyDescriptorUtils.findIndexedPropertyType(
@@ -477,8 +455,7 @@ class ExtendedBeanInfo implements BeanInfo {
}
@Override
@Nullable
public Class<?> getPropertyEditorClass() {
public @Nullable Class<?> getPropertyEditorClass() {
return this.propertyEditorClass;
}

View File

@@ -20,8 +20,9 @@ import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.lang.reflect.Method;
import org.jspecify.annotations.NonNull;
import org.springframework.core.Ordered;
import org.springframework.lang.NonNull;
/**
* Extension of {@link StandardBeanInfoFactory} that supports "non-standard"
@@ -43,8 +44,7 @@ import org.springframework.lang.NonNull;
public class ExtendedBeanInfoFactory extends StandardBeanInfoFactory {
@Override
@NonNull
public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
public @NonNull BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
BeanInfo beanInfo = super.getBeanInfo(beanClass);
return (supports(beanClass) ? new ExtendedBeanInfo(beanInfo) : beanInfo);
}

View File

@@ -16,7 +16,7 @@
package org.springframework.beans;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Thrown on an unrecoverable problem encountered in the

View File

@@ -24,13 +24,13 @@ import java.util.Objects;
import java.util.Set;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.core.BridgeMethodResolver;
import org.springframework.core.MethodParameter;
import org.springframework.core.ResolvableType;
import org.springframework.core.convert.Property;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
@@ -47,34 +47,25 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor {
private final Class<?> beanClass;
@Nullable
private final Method readMethod;
private final @Nullable Method readMethod;
@Nullable
private final Method writeMethod;
private final @Nullable Method writeMethod;
@Nullable
private Set<Method> ambiguousWriteMethods;
private @Nullable Set<Method> ambiguousWriteMethods;
private volatile boolean ambiguousWriteMethodsLogged;
@Nullable
private MethodParameter writeMethodParameter;
private @Nullable MethodParameter writeMethodParameter;
@Nullable
private volatile ResolvableType writeMethodType;
private volatile @Nullable ResolvableType writeMethodType;
@Nullable
private ResolvableType readMethodType;
private @Nullable ResolvableType readMethodType;
@Nullable
private volatile TypeDescriptor typeDescriptor;
private volatile @Nullable TypeDescriptor typeDescriptor;
@Nullable
private Class<?> propertyType;
private @Nullable Class<?> propertyType;
@Nullable
private final Class<?> propertyEditorClass;
private final @Nullable Class<?> propertyEditorClass;
public GenericTypeAwarePropertyDescriptor(Class<?> beanClass, String propertyName,
@@ -136,14 +127,12 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor {
}
@Override
@Nullable
public Method getReadMethod() {
public @Nullable Method getReadMethod() {
return this.readMethod;
}
@Override
@Nullable
public Method getWriteMethod() {
public @Nullable Method getWriteMethod() {
return this.writeMethod;
}
@@ -158,8 +147,7 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor {
return this.writeMethod;
}
@Nullable
public Method getWriteMethodFallback(@Nullable Class<?> valueType) {
public @Nullable Method getWriteMethodFallback(@Nullable Class<?> valueType) {
if (this.ambiguousWriteMethods != null) {
for (Method method : this.ambiguousWriteMethods) {
Class<?> paramType = method.getParameterTypes()[0];
@@ -171,8 +159,7 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor {
return null;
}
@Nullable
public Method getUniqueWriteMethodFallback() {
public @Nullable Method getUniqueWriteMethodFallback() {
if (this.ambiguousWriteMethods != null && this.ambiguousWriteMethods.size() == 1) {
return this.ambiguousWriteMethods.iterator().next();
}
@@ -213,14 +200,12 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor {
}
@Override
@Nullable
public Class<?> getPropertyType() {
public @Nullable Class<?> getPropertyType() {
return this.propertyType;
}
@Override
@Nullable
public Class<?> getPropertyEditorClass() {
public @Nullable Class<?> getPropertyEditorClass() {
return this.propertyEditorClass;
}

View File

@@ -16,7 +16,7 @@
package org.springframework.beans;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Exception thrown when referring to an invalid bean property.

View File

@@ -16,7 +16,7 @@
package org.springframework.beans;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Interface representing an object whose value set can be merged with

View File

@@ -18,7 +18,7 @@ package org.springframework.beans;
import java.beans.PropertyChangeEvent;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Thrown when a bean property getter or setter method throws an exception,

View File

@@ -27,7 +27,8 @@ import java.util.Set;
import java.util.Spliterator;
import java.util.stream.Stream;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.util.StringUtils;
/**
@@ -45,8 +46,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
private final List<PropertyValue> propertyValueList;
@Nullable
private Set<String> processedProperties;
private @Nullable Set<String> processedProperties;
private volatile boolean converted;
@@ -268,8 +268,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
}
@Override
@Nullable
public PropertyValue getPropertyValue(String propertyName) {
public @Nullable PropertyValue getPropertyValue(String propertyName) {
for (PropertyValue pv : this.propertyValueList) {
if (pv.getName().equals(propertyName)) {
return pv;
@@ -286,8 +285,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
* @see #getPropertyValue(String)
* @see PropertyValue#getValue()
*/
@Nullable
public Object get(String propertyName) {
public @Nullable Object get(String propertyName) {
PropertyValue pv = getPropertyValue(propertyName);
return (pv != null ? pv.getValue() : null);
}

View File

@@ -16,7 +16,7 @@
package org.springframework.beans;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Exception thrown on an attempt to set the value of a property that
@@ -29,8 +29,7 @@ import org.springframework.lang.Nullable;
@SuppressWarnings("serial")
public class NotWritablePropertyException extends InvalidPropertyException {
@Nullable
private final String[] possibleMatches;
private final String @Nullable [] possibleMatches;
/**
@@ -86,8 +85,7 @@ public class NotWritablePropertyException extends InvalidPropertyException {
* Return suggestions for actual bean property names that closely match
* the invalid property name, if any.
*/
@Nullable
public String[] getPossibleMatches() {
public String @Nullable [] getPossibleMatches() {
return this.possibleMatches;
}

View File

@@ -18,7 +18,7 @@ package org.springframework.beans;
import java.beans.PropertyChangeEvent;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Superclass for exceptions related to a property access,
@@ -30,8 +30,7 @@ import org.springframework.lang.Nullable;
@SuppressWarnings("serial")
public abstract class PropertyAccessException extends BeansException {
@Nullable
private final PropertyChangeEvent propertyChangeEvent;
private final @Nullable PropertyChangeEvent propertyChangeEvent;
/**
@@ -61,24 +60,21 @@ public abstract class PropertyAccessException extends BeansException {
* <p>May be {@code null}; only available if an actual bean property
* was affected.
*/
@Nullable
public PropertyChangeEvent getPropertyChangeEvent() {
public @Nullable PropertyChangeEvent getPropertyChangeEvent() {
return this.propertyChangeEvent;
}
/**
* Return the name of the affected property, if available.
*/
@Nullable
public String getPropertyName() {
public @Nullable String getPropertyName() {
return (this.propertyChangeEvent != null ? this.propertyChangeEvent.getPropertyName() : null);
}
/**
* Return the affected value that was about to be set, if any.
*/
@Nullable
public Object getValue() {
public @Nullable Object getValue() {
return (this.propertyChangeEvent != null ? this.propertyChangeEvent.getNewValue() : null);
}

View File

@@ -18,8 +18,9 @@ package org.springframework.beans;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.lang.Nullable;
/**
* Common interface for classes that can access named properties
@@ -101,8 +102,7 @@ public interface PropertyAccessor {
* @throws PropertyAccessException if the property was valid but the
* accessor method failed
*/
@Nullable
Class<?> getPropertyType(String propertyName) throws BeansException;
@Nullable Class<?> getPropertyType(String propertyName) throws BeansException;
/**
* Return a type descriptor for the specified property:
@@ -114,8 +114,7 @@ public interface PropertyAccessor {
* @throws PropertyAccessException if the property was valid but the
* accessor method failed
*/
@Nullable
TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException;
@Nullable TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException;
/**
* Get the current value of the specified property.
@@ -127,8 +126,7 @@ public interface PropertyAccessor {
* @throws PropertyAccessException if the property was valid but the
* accessor method failed
*/
@Nullable
Object getPropertyValue(String propertyName) throws BeansException;
@Nullable Object getPropertyValue(String propertyName) throws BeansException;
/**
* Set the specified value as current property value.

View File

@@ -16,7 +16,7 @@
package org.springframework.beans;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Utility methods for classes that perform bean property access
@@ -173,8 +173,7 @@ public abstract class PropertyAccessorUtils {
* (as array of the same size)
* @see #canonicalPropertyName(String)
*/
@Nullable
public static String[] canonicalPropertyNames(@Nullable String[] propertyNames) {
public static String @Nullable [] canonicalPropertyNames(String @Nullable [] propertyNames) {
if (propertyNames == null) {
return null;
}

View File

@@ -20,7 +20,8 @@ import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.StringJoiner;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -73,8 +74,7 @@ public class PropertyBatchUpdateException extends BeansException {
/**
* Return the exception for this field, or {@code null} if there isn't any.
*/
@Nullable
public PropertyAccessException getPropertyAccessException(String propertyName) {
public @Nullable PropertyAccessException getPropertyAccessException(String propertyName) {
for (PropertyAccessException pae : this.propertyAccessExceptions) {
if (ObjectUtils.nullSafeEquals(propertyName, pae.getPropertyName())) {
return pae;

View File

@@ -26,7 +26,8 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@@ -141,8 +142,7 @@ abstract class PropertyDescriptorUtils {
/**
* See {@link java.beans.PropertyDescriptor#findPropertyType}.
*/
@Nullable
public static Class<?> findPropertyType(@Nullable Method readMethod, @Nullable Method writeMethod)
public static @Nullable Class<?> findPropertyType(@Nullable Method readMethod, @Nullable Method writeMethod)
throws IntrospectionException {
Class<?> propertyType = null;
@@ -186,8 +186,7 @@ abstract class PropertyDescriptorUtils {
/**
* See {@link java.beans.IndexedPropertyDescriptor#findIndexedPropertyType}.
*/
@Nullable
public static Class<?> findIndexedPropertyType(String name, @Nullable Class<?> propertyType,
public static @Nullable Class<?> findIndexedPropertyType(String name, @Nullable Class<?> propertyType,
@Nullable Method indexedReadMethod, @Nullable Method indexedWriteMethod) throws IntrospectionException {
Class<?> indexedPropertyType = null;
@@ -264,11 +263,9 @@ abstract class PropertyDescriptorUtils {
*/
private static class BasicPropertyDescriptor extends PropertyDescriptor {
@Nullable
private Method readMethod;
private @Nullable Method readMethod;
@Nullable
private Method writeMethod;
private @Nullable Method writeMethod;
private final List<Method> alternativeWriteMethods = new ArrayList<>();
@@ -284,8 +281,7 @@ abstract class PropertyDescriptorUtils {
}
@Override
@Nullable
public Method getReadMethod() {
public @Nullable Method getReadMethod() {
return this.readMethod;
}
@@ -303,8 +299,7 @@ abstract class PropertyDescriptorUtils {
}
@Override
@Nullable
public Method getWriteMethod() {
public @Nullable Method getWriteMethod() {
if (this.writeMethod == null && !this.alternativeWriteMethods.isEmpty()) {
if (this.readMethod == null) {
return this.alternativeWriteMethods.get(0);

View File

@@ -18,7 +18,7 @@ package org.springframework.beans;
import java.beans.PropertyEditor;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Encapsulates methods for registering JavaBeans {@link PropertyEditor PropertyEditors}.
@@ -76,7 +76,6 @@ public interface PropertyEditorRegistry {
* {@code null} if looking for an editor for all properties of the given type
* @return the registered editor, or {@code null} if none
*/
@Nullable
PropertyEditor findCustomEditor(@Nullable Class<?> requiredType, @Nullable String propertyPath);
@Nullable PropertyEditor findCustomEditor(@Nullable Class<?> requiredType, @Nullable String propertyPath);
}

View File

@@ -44,6 +44,7 @@ import java.util.TimeZone;
import java.util.UUID;
import java.util.regex.Pattern;
import org.jspecify.annotations.Nullable;
import org.xml.sax.InputSource;
import org.springframework.beans.propertyeditors.ByteArrayPropertyEditor;
@@ -74,7 +75,6 @@ import org.springframework.beans.propertyeditors.ZoneIdEditor;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourceArrayPropertyEditor;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
/**
@@ -92,27 +92,21 @@ import org.springframework.util.ClassUtils;
*/
public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
@Nullable
private ConversionService conversionService;
private @Nullable ConversionService conversionService;
private boolean defaultEditorsActive = false;
private boolean configValueEditorsActive = false;
@Nullable
private Map<Class<?>, PropertyEditor> defaultEditors;
private @Nullable Map<Class<?>, PropertyEditor> defaultEditors;
@Nullable
private Map<Class<?>, PropertyEditor> overriddenDefaultEditors;
private @Nullable Map<Class<?>, PropertyEditor> overriddenDefaultEditors;
@Nullable
private Map<Class<?>, PropertyEditor> customEditors;
private @Nullable Map<Class<?>, PropertyEditor> customEditors;
@Nullable
private Map<String, CustomEditorHolder> customEditorsForPath;
private @Nullable Map<String, CustomEditorHolder> customEditorsForPath;
@Nullable
private Map<Class<?>, PropertyEditor> customEditorCache;
private @Nullable Map<Class<?>, PropertyEditor> customEditorCache;
/**
@@ -126,8 +120,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
/**
* Return the associated ConversionService, if any.
*/
@Nullable
public ConversionService getConversionService() {
public @Nullable ConversionService getConversionService() {
return this.conversionService;
}
@@ -178,9 +171,8 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
* @return the default editor, or {@code null} if none found
* @see #registerDefaultEditors
*/
@Nullable
@SuppressWarnings("NullAway")
public PropertyEditor getDefaultEditor(Class<?> requiredType) {
public @Nullable PropertyEditor getDefaultEditor(Class<?> requiredType) {
if (!this.defaultEditorsActive) {
return null;
}
@@ -312,8 +304,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
}
@Override
@Nullable
public PropertyEditor findCustomEditor(@Nullable Class<?> requiredType, @Nullable String propertyPath) {
public @Nullable PropertyEditor findCustomEditor(@Nullable Class<?> requiredType, @Nullable String propertyPath) {
Class<?> requiredTypeToUse = requiredType;
if (propertyPath != null) {
if (this.customEditorsForPath != null) {
@@ -372,8 +363,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
* @return the type of the property, or {@code null} if not determinable
* @see BeanWrapper#getPropertyType(String)
*/
@Nullable
protected Class<?> getPropertyType(String propertyPath) {
protected @Nullable Class<?> getPropertyType(String propertyPath) {
return null;
}
@@ -383,8 +373,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
* @param requiredType the type to look for
* @return the custom editor, or {@code null} if none specific for this property
*/
@Nullable
private PropertyEditor getCustomEditor(String propertyName, @Nullable Class<?> requiredType) {
private @Nullable PropertyEditor getCustomEditor(String propertyName, @Nullable Class<?> requiredType) {
CustomEditorHolder holder =
(this.customEditorsForPath != null ? this.customEditorsForPath.get(propertyName) : null);
return (holder != null ? holder.getPropertyEditor(requiredType) : null);
@@ -398,8 +387,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
* @return the custom editor, or {@code null} if none found for this type
* @see java.beans.PropertyEditor#getAsText()
*/
@Nullable
private PropertyEditor getCustomEditor(@Nullable Class<?> requiredType) {
private @Nullable PropertyEditor getCustomEditor(@Nullable Class<?> requiredType) {
if (requiredType == null || this.customEditors == null) {
return null;
}
@@ -438,8 +426,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
* @param propertyName the name of the property
* @return the property type, or {@code null} if not determinable
*/
@Nullable
protected Class<?> guessPropertyTypeFromEditors(String propertyName) {
protected @Nullable Class<?> guessPropertyTypeFromEditors(String propertyName) {
if (this.customEditorsForPath != null) {
CustomEditorHolder editorHolder = this.customEditorsForPath.get(propertyName);
if (editorHolder == null) {
@@ -526,8 +513,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
private final PropertyEditor propertyEditor;
@Nullable
private final Class<?> registeredType;
private final @Nullable Class<?> registeredType;
private CustomEditorHolder(PropertyEditor propertyEditor, @Nullable Class<?> registeredType) {
this.propertyEditor = propertyEditor;
@@ -538,13 +524,11 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
return this.propertyEditor;
}
@Nullable
private Class<?> getRegisteredType() {
private @Nullable Class<?> getRegisteredType() {
return this.registeredType;
}
@Nullable
private PropertyEditor getPropertyEditor(@Nullable Class<?> requiredType) {
private @Nullable PropertyEditor getPropertyEditor(@Nullable Class<?> requiredType) {
// Special case: If no required type specified, which usually only happens for
// Collection elements, or required type is not assignable to registered type,
// which usually only happens for generic properties of type Object -

View File

@@ -18,7 +18,8 @@ package org.springframework.beans;
import java.io.Serializable;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -44,23 +45,19 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri
private final String name;
@Nullable
private final Object value;
private final @Nullable Object value;
private boolean optional = false;
private boolean converted = false;
@Nullable
private Object convertedValue;
private @Nullable Object convertedValue;
/** Package-visible field that indicates whether conversion is necessary. */
@Nullable
volatile Boolean conversionNecessary;
volatile @Nullable Boolean conversionNecessary;
/** Package-visible field for caching the resolved property path tokens. */
@Nullable
transient volatile Object resolvedTokens;
transient volatile @Nullable Object resolvedTokens;
/**
@@ -122,8 +119,7 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri
* It is the responsibility of the BeanWrapper implementation to
* perform type conversion.
*/
@Nullable
public Object getValue() {
public @Nullable Object getValue() {
return this.value;
}
@@ -181,8 +177,7 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri
* Return the converted value of this property value,
* after processed type conversion.
*/
@Nullable
public synchronized Object getConvertedValue() {
public synchronized @Nullable Object getConvertedValue() {
return this.convertedValue;
}

View File

@@ -23,7 +23,7 @@ import java.util.Spliterators;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Holder containing one or more {@link PropertyValue} objects,
@@ -72,8 +72,7 @@ public interface PropertyValues extends Iterable<PropertyValue> {
* @param propertyName the name to search for
* @return the property value, or {@code null} if none
*/
@Nullable
PropertyValue getPropertyValue(String propertyName);
@Nullable PropertyValue getPropertyValue(String propertyName);
/**
* Return the changes since the previous PropertyValues.

View File

@@ -23,8 +23,9 @@ import java.beans.PropertyDescriptor;
import java.beans.SimpleBeanInfo;
import java.util.Collection;
import org.jspecify.annotations.NonNull;
import org.springframework.core.Ordered;
import org.springframework.lang.NonNull;
/**
* {@link BeanInfoFactory} implementation that bypasses the standard {@link java.beans.Introspector}
@@ -47,8 +48,7 @@ import org.springframework.lang.NonNull;
class SimpleBeanInfoFactory implements BeanInfoFactory, Ordered {
@Override
@NonNull
public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
public @NonNull BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
Collection<? extends PropertyDescriptor> pds =
PropertyDescriptorUtils.determineBasicProperties(beanClass);

View File

@@ -20,9 +20,10 @@ import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import org.jspecify.annotations.NonNull;
import org.springframework.core.Ordered;
import org.springframework.core.SpringProperties;
import org.springframework.lang.NonNull;
/**
* {@link BeanInfoFactory} implementation that performs standard
@@ -66,8 +67,7 @@ public class StandardBeanInfoFactory implements BeanInfoFactory, Ordered {
@Override
@NonNull
public BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
public @NonNull BeanInfo getBeanInfo(Class<?> beanClass) throws IntrospectionException {
BeanInfo beanInfo = (shouldIntrospectorIgnoreBeaninfoClasses ?
Introspector.getBeanInfo(beanClass, Introspector.IGNORE_ALL_BEANINFO) :
Introspector.getBeanInfo(beanClass));

View File

@@ -18,9 +18,10 @@ package org.springframework.beans;
import java.lang.reflect.Field;
import org.jspecify.annotations.Nullable;
import org.springframework.core.MethodParameter;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.lang.Nullable;
/**
* Interface that defines type conversion methods. Typically (but not necessarily)
@@ -51,8 +52,7 @@ public interface TypeConverter {
* @see org.springframework.core.convert.ConversionService
* @see org.springframework.core.convert.converter.Converter
*/
@Nullable
<T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType) throws TypeMismatchException;
<T> @Nullable T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType) throws TypeMismatchException;
/**
* Convert the value to the required type (if necessary from a String).
@@ -70,8 +70,7 @@ public interface TypeConverter {
* @see org.springframework.core.convert.ConversionService
* @see org.springframework.core.convert.converter.Converter
*/
@Nullable
<T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType,
<T> @Nullable T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType,
@Nullable MethodParameter methodParam) throws TypeMismatchException;
/**
@@ -90,8 +89,7 @@ public interface TypeConverter {
* @see org.springframework.core.convert.ConversionService
* @see org.springframework.core.convert.converter.Converter
*/
@Nullable
<T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType, @Nullable Field field)
<T> @Nullable T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType, @Nullable Field field)
throws TypeMismatchException;
/**
@@ -110,8 +108,7 @@ public interface TypeConverter {
* @see org.springframework.core.convert.ConversionService
* @see org.springframework.core.convert.converter.Converter
*/
@Nullable
default <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType,
default <T> @Nullable T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType,
@Nullable TypeDescriptor typeDescriptor) throws TypeMismatchException {
throw new UnsupportedOperationException("TypeDescriptor resolution not supported");

View File

@@ -28,12 +28,12 @@ import java.util.Optional;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.core.CollectionFactory;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.NumberUtils;
@@ -60,8 +60,7 @@ class TypeConverterDelegate {
private final PropertyEditorRegistrySupport propertyEditorRegistry;
@Nullable
private final Object targetObject;
private final @Nullable Object targetObject;
/**
@@ -93,8 +92,7 @@ class TypeConverterDelegate {
* @return the new value, possibly the result of type conversion
* @throws IllegalArgumentException if type conversion failed
*/
@Nullable
public <T> T convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue,
public <T> @Nullable T convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue,
Object newValue, @Nullable Class<T> requiredType) throws IllegalArgumentException {
return convertIfNecessary(propertyName, oldValue, newValue, requiredType, TypeDescriptor.valueOf(requiredType));
@@ -113,8 +111,7 @@ class TypeConverterDelegate {
* @throws IllegalArgumentException if type conversion failed
*/
@SuppressWarnings("unchecked")
@Nullable
public <T> T convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, @Nullable Object newValue,
public <T> @Nullable T convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, @Nullable Object newValue,
@Nullable Class<T> requiredType, @Nullable TypeDescriptor typeDescriptor) throws IllegalArgumentException {
// Custom editor for this type?
@@ -337,8 +334,7 @@ class TypeConverterDelegate {
* @param requiredType the type to find an editor for
* @return the corresponding editor, or {@code null} if none
*/
@Nullable
private PropertyEditor findDefaultEditor(@Nullable Class<?> requiredType) {
private @Nullable PropertyEditor findDefaultEditor(@Nullable Class<?> requiredType) {
PropertyEditor editor = null;
if (requiredType != null) {
// No custom editor -> check BeanWrapperImpl's default editors.
@@ -362,8 +358,7 @@ class TypeConverterDelegate {
* @return the new value, possibly the result of type conversion
* @throws IllegalArgumentException if type conversion failed
*/
@Nullable
private Object doConvertValue(@Nullable Object oldValue, @Nullable Object newValue,
private @Nullable Object doConvertValue(@Nullable Object oldValue, @Nullable Object newValue,
@Nullable Class<?> requiredType, @Nullable PropertyEditor editor) {
Object convertedValue = newValue;
@@ -628,15 +623,13 @@ class TypeConverterDelegate {
return (originalAllowed ? original : convertedCopy);
}
@Nullable
private String buildIndexedPropertyName(@Nullable String propertyName, int index) {
private @Nullable String buildIndexedPropertyName(@Nullable String propertyName, int index) {
return (propertyName != null ?
propertyName + PropertyAccessor.PROPERTY_KEY_PREFIX + index + PropertyAccessor.PROPERTY_KEY_SUFFIX :
null);
}
@Nullable
private String buildKeyedPropertyName(@Nullable String propertyName, Object key) {
private @Nullable String buildKeyedPropertyName(@Nullable String propertyName, Object key) {
return (propertyName != null ?
propertyName + PropertyAccessor.PROPERTY_KEY_PREFIX + key + PropertyAccessor.PROPERTY_KEY_SUFFIX :
null);

View File

@@ -18,11 +18,12 @@ package org.springframework.beans;
import java.lang.reflect.Field;
import org.jspecify.annotations.Nullable;
import org.springframework.core.MethodParameter;
import org.springframework.core.convert.ConversionException;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -35,19 +36,16 @@ import org.springframework.util.Assert;
*/
public abstract class TypeConverterSupport extends PropertyEditorRegistrySupport implements TypeConverter {
@Nullable
TypeConverterDelegate typeConverterDelegate;
@Nullable TypeConverterDelegate typeConverterDelegate;
@Override
@Nullable
public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType) throws TypeMismatchException {
public <T> @Nullable T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType) throws TypeMismatchException {
return convertIfNecessary(null, value, requiredType, TypeDescriptor.valueOf(requiredType));
}
@Override
@Nullable
public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType,
public <T> @Nullable T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType,
@Nullable MethodParameter methodParam) throws TypeMismatchException {
return convertIfNecessary((methodParam != null ? methodParam.getParameterName() : null), value, requiredType,
@@ -55,8 +53,7 @@ public abstract class TypeConverterSupport extends PropertyEditorRegistrySupport
}
@Override
@Nullable
public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType, @Nullable Field field)
public <T> @Nullable T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType, @Nullable Field field)
throws TypeMismatchException {
return convertIfNecessary((field != null ? field.getName() : null), value, requiredType,
@@ -64,15 +61,13 @@ public abstract class TypeConverterSupport extends PropertyEditorRegistrySupport
}
@Override
@Nullable
public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType,
public <T> @Nullable T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType,
@Nullable TypeDescriptor typeDescriptor) throws TypeMismatchException {
return convertIfNecessary(null, value, requiredType, typeDescriptor);
}
@Nullable
private <T> T convertIfNecessary(@Nullable String propertyName, @Nullable Object value,
private <T> @Nullable T convertIfNecessary(@Nullable String propertyName, @Nullable Object value,
@Nullable Class<T> requiredType, @Nullable TypeDescriptor typeDescriptor) throws TypeMismatchException {
Assert.state(this.typeConverterDelegate != null, "No TypeConverterDelegate");

View File

@@ -18,7 +18,8 @@ package org.springframework.beans;
import java.beans.PropertyChangeEvent;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -37,14 +38,11 @@ public class TypeMismatchException extends PropertyAccessException {
public static final String ERROR_CODE = "typeMismatch";
@Nullable
private String propertyName;
private @Nullable String propertyName;
@Nullable
private final transient Object value;
private final transient @Nullable Object value;
@Nullable
private final Class<?> requiredType;
private final @Nullable Class<?> requiredType;
/**
@@ -123,8 +121,7 @@ public class TypeMismatchException extends PropertyAccessException {
* Return the name of the affected property, if available.
*/
@Override
@Nullable
public String getPropertyName() {
public @Nullable String getPropertyName() {
return this.propertyName;
}
@@ -132,16 +129,14 @@ public class TypeMismatchException extends PropertyAccessException {
* Return the offending value (may be {@code null}).
*/
@Override
@Nullable
public Object getValue() {
public @Nullable Object getValue() {
return this.value;
}
/**
* Return the required target type, if any.
*/
@Nullable
public Class<?> getRequiredType() {
public @Nullable Class<?> getRequiredType() {
return this.requiredType;
}

View File

@@ -21,9 +21,10 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.FatalBeanException;
import org.springframework.core.NestedRuntimeException;
import org.springframework.lang.Nullable;
/**
* Exception thrown when a BeanFactory encounters an error when
@@ -34,14 +35,11 @@ import org.springframework.lang.Nullable;
@SuppressWarnings("serial")
public class BeanCreationException extends FatalBeanException {
@Nullable
private final String beanName;
private final @Nullable String beanName;
@Nullable
private final String resourceDescription;
private final @Nullable String resourceDescription;
@Nullable
private List<Throwable> relatedCauses;
private @Nullable List<Throwable> relatedCauses;
/**
@@ -120,16 +118,14 @@ public class BeanCreationException extends FatalBeanException {
* Return the description of the resource that the bean
* definition came from, if any.
*/
@Nullable
public String getResourceDescription() {
public @Nullable String getResourceDescription() {
return this.resourceDescription;
}
/**
* Return the name of the bean requested, if any.
*/
@Nullable
public String getBeanName() {
public @Nullable String getBeanName() {
return this.beanName;
}
@@ -150,8 +146,7 @@ public class BeanCreationException extends FatalBeanException {
* Return the related causes, if any.
* @return the array of related causes, or {@code null} if none
*/
@Nullable
public Throwable[] getRelatedCauses() {
public Throwable @Nullable [] getRelatedCauses() {
if (this.relatedCauses == null) {
return null;
}

View File

@@ -16,8 +16,9 @@
package org.springframework.beans.factory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.FatalBeanException;
import org.springframework.lang.Nullable;
/**
* Exception thrown when a BeanFactory encounters an invalid bean definition:
@@ -30,11 +31,9 @@ import org.springframework.lang.Nullable;
@SuppressWarnings("serial")
public class BeanDefinitionStoreException extends FatalBeanException {
@Nullable
private final String resourceDescription;
private final @Nullable String resourceDescription;
@Nullable
private final String beanName;
private final @Nullable String beanName;
/**
@@ -113,16 +112,14 @@ public class BeanDefinitionStoreException extends FatalBeanException {
/**
* Return the description of the resource that the bean definition came from, if available.
*/
@Nullable
public String getResourceDescription() {
public @Nullable String getResourceDescription() {
return this.resourceDescription;
}
/**
* Return the name of the bean, if available.
*/
@Nullable
public String getBeanName() {
public @Nullable String getBeanName() {
return this.beanName;
}

View File

@@ -16,9 +16,10 @@
package org.springframework.beans.factory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable;
/**
* The root interface for accessing a Spring bean container.
@@ -182,7 +183,7 @@ public interface BeanFactory {
* @throws BeansException if the bean could not be created
* @since 2.5
*/
Object getBean(String name, Object... args) throws BeansException;
Object getBean(String name, @Nullable Object @Nullable ... args) throws BeansException;
/**
* Return the bean instance that uniquely matches the given object type, if any.
@@ -220,7 +221,7 @@ public interface BeanFactory {
* @throws BeansException if the bean could not be created
* @since 4.1
*/
<T> T getBean(Class<T> requiredType, Object... args) throws BeansException;
<T> T getBean(Class<T> requiredType, @Nullable Object @Nullable ... args) throws BeansException;
/**
* Return a provider for the specified bean, allowing for lazy on-demand retrieval
@@ -357,8 +358,7 @@ public interface BeanFactory {
* @see #getBean
* @see #isTypeMatch
*/
@Nullable
Class<?> getType(String name) throws NoSuchBeanDefinitionException;
@Nullable Class<?> getType(String name) throws NoSuchBeanDefinitionException;
/**
* Determine the type of the bean with the given name. More specifically,
@@ -378,8 +378,7 @@ public interface BeanFactory {
* @see #getBean
* @see #isTypeMatch
*/
@Nullable
Class<?> getType(String name, boolean allowFactoryBeanInit) throws NoSuchBeanDefinitionException;
@Nullable Class<?> getType(String name, boolean allowFactoryBeanInit) throws NoSuchBeanDefinitionException;
/**
* Return the aliases for the given bean name, if any.

View File

@@ -24,9 +24,10 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

View File

@@ -16,8 +16,9 @@
package org.springframework.beans.factory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.FatalBeanException;
import org.springframework.lang.Nullable;
/**
* Exception thrown when the BeanFactory cannot load the specified class
@@ -29,13 +30,11 @@ import org.springframework.lang.Nullable;
@SuppressWarnings("serial")
public class CannotLoadBeanClassException extends FatalBeanException {
@Nullable
private final String resourceDescription;
private final @Nullable String resourceDescription;
private final String beanName;
@Nullable
private final String beanClassName;
private final @Nullable String beanClassName;
/**
@@ -80,8 +79,7 @@ public class CannotLoadBeanClassException extends FatalBeanException {
* Return the description of the resource that the bean
* definition came from.
*/
@Nullable
public String getResourceDescription() {
public @Nullable String getResourceDescription() {
return this.resourceDescription;
}
@@ -95,8 +93,7 @@ public class CannotLoadBeanClassException extends FatalBeanException {
/**
* Return the name of the class we were trying to load.
*/
@Nullable
public String getBeanClassName() {
public @Nullable String getBeanClassName() {
return this.beanClassName;
}

View File

@@ -16,7 +16,7 @@
package org.springframework.beans.factory;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Interface to be implemented by objects used within a {@link BeanFactory} which
@@ -92,8 +92,7 @@ public interface FactoryBean<T> {
* @throws Exception in case of creation errors
* @see FactoryBeanNotInitializedException
*/
@Nullable
T getObject() throws Exception;
@Nullable T getObject() throws Exception;
/**
* Return the type of object that this FactoryBean creates,
@@ -114,8 +113,7 @@ public interface FactoryBean<T> {
* or {@code null} if not known at the time of the call
* @see ListableBeanFactory#getBeansOfType
*/
@Nullable
Class<?> getObjectType();
@Nullable Class<?> getObjectType();
/**
* Is the object managed by this factory a singleton? That is,

View File

@@ -16,7 +16,7 @@
package org.springframework.beans.factory;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Sub-interface implemented by bean factories that can be part
@@ -36,8 +36,7 @@ public interface HierarchicalBeanFactory extends BeanFactory {
/**
* Return the parent bean factory, or {@code null} if there is none.
*/
@Nullable
BeanFactory getParentBeanFactory();
@Nullable BeanFactory getParentBeanFactory();
/**
* Return whether the local bean factory contains a bean of the given name,

View File

@@ -22,8 +22,9 @@ import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.util.Objects;
import org.jspecify.annotations.Nullable;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -42,14 +43,11 @@ import org.springframework.util.ObjectUtils;
*/
public class InjectionPoint {
@Nullable
protected MethodParameter methodParameter;
protected @Nullable MethodParameter methodParameter;
@Nullable
protected Field field;
protected @Nullable Field field;
@Nullable
private volatile Annotation[] fieldAnnotations;
private volatile Annotation @Nullable [] fieldAnnotations;
/**
@@ -93,8 +91,7 @@ public class InjectionPoint {
* <p>Note: Either MethodParameter or Field is available.
* @return the MethodParameter, or {@code null} if none
*/
@Nullable
public MethodParameter getMethodParameter() {
public @Nullable MethodParameter getMethodParameter() {
return this.methodParameter;
}
@@ -103,8 +100,7 @@ public class InjectionPoint {
* <p>Note: Either MethodParameter or Field is available.
* @return the Field, or {@code null} if none
*/
@Nullable
public Field getField() {
public @Nullable Field getField() {
return this.field;
}
@@ -142,8 +138,7 @@ public class InjectionPoint {
* @return the annotation instance, or {@code null} if none found
* @since 4.3.9
*/
@Nullable
public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
public <A extends Annotation> @Nullable A getAnnotation(Class<A> annotationType) {
return (this.field != null ? this.field.getAnnotation(annotationType) :
obtainMethodParameter().getParameterAnnotation(annotationType));
}

View File

@@ -20,9 +20,10 @@ import java.lang.annotation.Annotation;
import java.util.Map;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable;
/**
* Extension of the {@link BeanFactory} interface to be implemented by bean factories
@@ -375,8 +376,7 @@ public interface ListableBeanFactory extends BeanFactory {
* @see #getBeansWithAnnotation(Class)
* @see #getType(String)
*/
@Nullable
<A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType)
<A extends Annotation> @Nullable A findAnnotationOnBean(String beanName, Class<A> annotationType)
throws NoSuchBeanDefinitionException;
/**
@@ -397,8 +397,7 @@ public interface ListableBeanFactory extends BeanFactory {
* @see #getBeansWithAnnotation(Class)
* @see #getType(String, boolean)
*/
@Nullable
<A extends Annotation> A findAnnotationOnBean(
<A extends Annotation> @Nullable A findAnnotationOnBean(
String beanName, Class<A> annotationType, boolean allowFactoryBeanInit)
throws NoSuchBeanDefinitionException;

View File

@@ -16,9 +16,10 @@
package org.springframework.beans.factory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable;
/**
* Exception thrown when a {@code BeanFactory} is asked for a bean instance for which it
@@ -35,11 +36,9 @@ import org.springframework.lang.Nullable;
@SuppressWarnings("serial")
public class NoSuchBeanDefinitionException extends BeansException {
@Nullable
private final String beanName;
private final @Nullable String beanName;
@Nullable
private final ResolvableType resolvableType;
private final @Nullable ResolvableType resolvableType;
/**
@@ -107,8 +106,7 @@ public class NoSuchBeanDefinitionException extends BeansException {
/**
* Return the name of the missing bean, if it was a lookup <em>by name</em> that failed.
*/
@Nullable
public String getBeanName() {
public @Nullable String getBeanName() {
return this.beanName;
}
@@ -116,8 +114,7 @@ public class NoSuchBeanDefinitionException extends BeansException {
* Return the required type of the missing bean, if it was a lookup <em>by type</em>
* that failed.
*/
@Nullable
public Class<?> getBeanType() {
public @Nullable Class<?> getBeanType() {
return (this.resolvableType != null ? this.resolvableType.resolve() : null);
}
@@ -126,8 +123,7 @@ public class NoSuchBeanDefinitionException extends BeansException {
* <em>by type</em> that failed.
* @since 4.3.4
*/
@Nullable
public ResolvableType getResolvableType() {
public @Nullable ResolvableType getResolvableType() {
return this.resolvableType;
}

View File

@@ -20,8 +20,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import org.jspecify.annotations.Nullable;
import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
@@ -38,8 +39,7 @@ public class NoUniqueBeanDefinitionException extends NoSuchBeanDefinitionExcepti
private final int numberOfBeansFound;
@Nullable
private final Collection<String> beanNamesFound;
private final @Nullable Collection<String> beanNamesFound;
/**
@@ -126,8 +126,7 @@ public class NoUniqueBeanDefinitionException extends NoSuchBeanDefinitionExcepti
* @since 4.3
* @see #getBeanType()
*/
@Nullable
public Collection<String> getBeanNamesFound() {
public @Nullable Collection<String> getBeanNamesFound() {
return this.beanNamesFound;
}

View File

@@ -21,9 +21,10 @@ import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Stream;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.core.OrderComparator;
import org.springframework.lang.Nullable;
/**
* A variant of {@link ObjectFactory} designed specifically for injection points,
@@ -88,8 +89,7 @@ public interface ObjectProvider<T> extends ObjectFactory<T>, Iterable<T> {
* @throws BeansException in case of creation errors
* @see #getObject()
*/
@Nullable
default T getIfAvailable() throws BeansException {
default @Nullable T getIfAvailable() throws BeansException {
try {
return getObject();
}
@@ -141,8 +141,7 @@ public interface ObjectProvider<T> extends ObjectFactory<T>, Iterable<T> {
* @throws BeansException in case of creation errors
* @see #getObject()
*/
@Nullable
default T getIfUnique() throws BeansException {
default @Nullable T getIfUnique() throws BeansException {
try {
return getObject();
}

View File

@@ -16,8 +16,9 @@
package org.springframework.beans.factory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
@@ -32,8 +33,7 @@ import org.springframework.util.StringUtils;
@SuppressWarnings("serial")
public class UnsatisfiedDependencyException extends BeanCreationException {
@Nullable
private final InjectionPoint injectionPoint;
private final @Nullable InjectionPoint injectionPoint;
/**
@@ -103,8 +103,7 @@ public class UnsatisfiedDependencyException extends BeanCreationException {
* Return the injection point (field or method/constructor parameter), if known.
* @since 4.3
*/
@Nullable
public InjectionPoint getInjectionPoint() {
public @Nullable InjectionPoint getInjectionPoint() {
return this.injectionPoint;
}

View File

@@ -16,10 +16,11 @@
package org.springframework.beans.factory.annotation;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.MethodMetadata;
import org.springframework.lang.Nullable;
/**
* Extended {@link org.springframework.beans.factory.config.BeanDefinition}
@@ -45,7 +46,6 @@ public interface AnnotatedBeanDefinition extends BeanDefinition {
* @return the factory method metadata, or {@code null} if none
* @since 4.1.1
*/
@Nullable
MethodMetadata getFactoryMethodMetadata();
@Nullable MethodMetadata getFactoryMethodMetadata();
}

View File

@@ -16,11 +16,12 @@
package org.springframework.beans.factory.annotation;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.MethodMetadata;
import org.springframework.core.type.StandardAnnotationMetadata;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -45,8 +46,7 @@ public class AnnotatedGenericBeanDefinition extends GenericBeanDefinition implem
private final AnnotationMetadata metadata;
@Nullable
private MethodMetadata factoryMethodMetadata;
private @Nullable MethodMetadata factoryMethodMetadata;
/**
@@ -100,8 +100,7 @@ public class AnnotatedGenericBeanDefinition extends GenericBeanDefinition implem
}
@Override
@Nullable
public final MethodMetadata getFactoryMethodMetadata() {
public final @Nullable MethodMetadata getFactoryMethodMetadata() {
return this.factoryMethodMetadata;
}

View File

@@ -16,9 +16,10 @@
package org.springframework.beans.factory.annotation;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.wiring.BeanWiringInfo;
import org.springframework.beans.factory.wiring.BeanWiringInfoResolver;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -38,8 +39,7 @@ import org.springframework.util.ClassUtils;
public class AnnotationBeanWiringInfoResolver implements BeanWiringInfoResolver {
@Override
@Nullable
public BeanWiringInfo resolveWiringInfo(Object beanInstance) {
public @Nullable BeanWiringInfo resolveWiringInfo(Object beanInstance) {
Assert.notNull(beanInstance, "Bean instance must not be null");
Configurable annotation = beanInstance.getClass().getAnnotation(Configurable.class);
return (annotation != null ? buildWiringInfo(beanInstance, annotation) : null);

View File

@@ -38,6 +38,7 @@ 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.aot.generate.AccessControl;
import org.springframework.aot.generate.GeneratedClass;
@@ -86,7 +87,6 @@ import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
import org.springframework.javapoet.ClassName;
import org.springframework.javapoet.CodeBlock;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
@@ -171,11 +171,9 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA
private int order = Ordered.LOWEST_PRECEDENCE - 2;
@Nullable
private ConfigurableListableBeanFactory beanFactory;
private @Nullable ConfigurableListableBeanFactory beanFactory;
@Nullable
private MetadataReaderFactory metadataReaderFactory;
private @Nullable MetadataReaderFactory metadataReaderFactory;
private final Set<String> lookupMethodsChecked = ConcurrentHashMap.newKeySet(256);
@@ -301,8 +299,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA
}
@Override
@Nullable
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
Class<?> beanClass = registeredBean.getBeanClass();
String beanName = registeredBean.getBeanName();
RootBeanDefinition beanDefinition = registeredBean.getMergedBeanDefinition();
@@ -321,8 +318,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA
return (Collection) metadata.getInjectedElements(propertyValues);
}
@Nullable
private AutowireCandidateResolver getAutowireCandidateResolver() {
private @Nullable AutowireCandidateResolver getAutowireCandidateResolver() {
if (this.beanFactory instanceof DefaultListableBeanFactory lbf) {
return lbf.getAutowireCandidateResolver();
}
@@ -350,8 +346,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA
}
@Override
@Nullable
public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, final String beanName)
public Constructor<?> @Nullable [] determineCandidateConstructors(Class<?> beanClass, final String beanName)
throws BeanCreationException {
checkLookupMethods(beanClass, beanName);
@@ -612,8 +607,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA
return InjectionMetadata.forElements(elements, clazz);
}
@Nullable
private MergedAnnotation<?> findAutowiredAnnotation(AccessibleObject ao) {
private @Nullable MergedAnnotation<?> findAutowiredAnnotation(AccessibleObject ao) {
MergedAnnotations annotations = MergedAnnotations.from(ao);
for (Class<? extends Annotation> type : this.autowiredAnnotationTypes) {
MergedAnnotation<?> annotation = annotations.get(type);
@@ -698,8 +692,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA
/**
* Resolve the specified cached method argument or field value.
*/
@Nullable
private Object resolveCachedArgument(@Nullable String beanName, @Nullable Object cachedArgument) {
private @Nullable Object resolveCachedArgument(@Nullable String beanName, @Nullable Object cachedArgument) {
if (cachedArgument instanceof DependencyDescriptor descriptor) {
Assert.state(this.beanFactory != null, "No BeanFactory available");
return this.beanFactory.resolveDependency(descriptor, beanName, null, null);
@@ -731,8 +724,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA
private volatile boolean cached;
@Nullable
private volatile Object cachedFieldValue;
private volatile @Nullable Object cachedFieldValue;
public AutowiredFieldElement(Field field, boolean required) {
super(field, null, required);
@@ -762,8 +754,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA
}
}
@Nullable
private Object resolveFieldValue(Field field, Object bean, @Nullable String beanName) {
private @Nullable Object resolveFieldValue(Field field, Object bean, @Nullable String beanName) {
DependencyDescriptor desc = new DependencyDescriptor(field, this.required);
desc.setContainingClass(bean.getClass());
Set<String> autowiredBeanNames = new LinkedHashSet<>(2);
@@ -809,8 +800,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA
private volatile boolean cached;
@Nullable
private volatile Object[] cachedMethodArguments;
private volatile Object @Nullable [] cachedMethodArguments;
public AutowiredMethodElement(Method method, boolean required, @Nullable PropertyDescriptor pd) {
super(method, pd, required);
@@ -848,8 +838,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA
}
}
@Nullable
private Object[] resolveCachedArguments(@Nullable String beanName, @Nullable Object[] cachedMethodArguments) {
private Object @Nullable [] resolveCachedArguments(@Nullable String beanName, Object @Nullable [] cachedMethodArguments) {
if (cachedMethodArguments == null) {
return null;
}
@@ -860,8 +849,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA
return arguments;
}
@Nullable
private Object[] resolveMethodArguments(Method method, Object bean, @Nullable String beanName) {
private Object @Nullable [] resolveMethodArguments(Method method, Object bean, @Nullable String beanName) {
int argumentCount = method.getParameterCount();
Object[] arguments = new Object[argumentCount];
DependencyDescriptor[] descriptors = new DependencyDescriptor[argumentCount];
@@ -949,8 +937,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA
private final Collection<AutowiredElement> autowiredElements;
@Nullable
private final AutowireCandidateResolver candidateResolver;
private final @Nullable AutowireCandidateResolver candidateResolver;
AotContribution(Class<?> target, Collection<AutowiredElement> autowiredElements,
@Nullable AutowireCandidateResolver candidateResolver) {

View File

@@ -22,6 +22,8 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Predicate;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryUtils;
@@ -34,7 +36,6 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.AutowireCandidateQualifier;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -146,8 +147,7 @@ public abstract class BeanFactoryAnnotationUtils {
* @return the associated qualifier value, or {@code null} if none
* @since 6.2
*/
@Nullable
public static String getQualifierValue(AnnotatedElement annotatedElement) {
public static @Nullable String getQualifierValue(AnnotatedElement annotatedElement) {
Qualifier qualifier = AnnotationUtils.getAnnotation(annotatedElement, Qualifier.class);
return (qualifier != null ? qualifier.value() : null);
}

View File

@@ -19,13 +19,14 @@ package org.springframework.beans.factory.annotation;
import java.lang.annotation.Annotation;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.Ordered;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
/**
@@ -51,11 +52,9 @@ public class CustomAutowireConfigurer implements BeanFactoryPostProcessor, BeanC
private int order = Ordered.LOWEST_PRECEDENCE; // default: same as non-Ordered
@Nullable
private Set<?> customQualifierTypes;
private @Nullable Set<?> customQualifierTypes;
@Nullable
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
public void setOrder(int order) {

View File

@@ -35,6 +35,7 @@ import java.util.stream.Stream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanCreationException;
@@ -47,7 +48,6 @@ import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.core.Ordered;
import org.springframework.core.PriorityOrdered;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ReflectionUtils;
@@ -113,8 +113,7 @@ public class InitDestroyAnnotationBeanPostProcessor implements DestructionAwareB
private int order = Ordered.LOWEST_PRECEDENCE;
@Nullable
private final transient Map<Class<?>, LifecycleMetadata> lifecycleMetadataCache = new ConcurrentHashMap<>(256);
private final transient @Nullable Map<Class<?>, LifecycleMetadata> lifecycleMetadataCache = new ConcurrentHashMap<>(256);
/**
@@ -183,8 +182,7 @@ public class InitDestroyAnnotationBeanPostProcessor implements DestructionAwareB
}
@Override
@Nullable
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
RootBeanDefinition beanDefinition = registeredBean.getMergedBeanDefinition();
beanDefinition.resolveDestroyMethodIfNecessary();
LifecycleMetadata metadata = findLifecycleMetadata(beanDefinition, registeredBean.getBeanClass());
@@ -205,7 +203,7 @@ public class InitDestroyAnnotationBeanPostProcessor implements DestructionAwareB
return metadata;
}
private static String[] safeMerge(@Nullable String[] existingNames, Collection<LifecycleMethod> detectedMethods) {
private static String[] safeMerge(String @Nullable [] existingNames, Collection<LifecycleMethod> detectedMethods) {
Stream<String> detectedNames = detectedMethods.stream().map(LifecycleMethod::getIdentifier);
Stream<String> mergedNames = (existingNames != null ?
Stream.concat(detectedNames, Stream.of(existingNames)) : detectedNames);
@@ -348,11 +346,9 @@ public class InitDestroyAnnotationBeanPostProcessor implements DestructionAwareB
private final Collection<LifecycleMethod> destroyMethods;
@Nullable
private volatile Set<LifecycleMethod> checkedInitMethods;
private volatile @Nullable Set<LifecycleMethod> checkedInitMethods;
@Nullable
private volatile Set<LifecycleMethod> checkedDestroyMethods;
private volatile @Nullable Set<LifecycleMethod> checkedDestroyMethods;
public LifecycleMetadata(Class<?> beanClass, Collection<LifecycleMethod> initMethods,
Collection<LifecycleMethod> destroyMethods) {

View File

@@ -25,11 +25,12 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.lang.Contract;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ReflectionUtils;
@@ -72,8 +73,7 @@ public class InjectionMetadata {
private final Collection<InjectedElement> injectedElements;
@Nullable
private volatile Set<InjectedElement> checkedElements;
private volatile @Nullable Set<InjectedElement> checkedElements;
/**
@@ -198,11 +198,9 @@ public class InjectionMetadata {
protected final boolean isField;
@Nullable
protected final PropertyDescriptor pd;
protected final @Nullable PropertyDescriptor pd;
@Nullable
protected volatile Boolean skip;
protected volatile @Nullable Boolean skip;
protected InjectedElement(Member member, @Nullable PropertyDescriptor pd) {
this.member = member;
@@ -335,8 +333,7 @@ public class InjectionMetadata {
/**
* Either this or {@link #inject} needs to be overridden.
*/
@Nullable
protected Object getResourceToInject(Object target, @Nullable String requestingBeanName) {
protected @Nullable Object getResourceToInject(Object target, @Nullable String requestingBeanName) {
return null;
}

View File

@@ -18,10 +18,11 @@ package org.springframework.beans.factory.annotation;
import java.util.stream.Stream;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.TypeReference;
import org.springframework.lang.Nullable;
/**
* {@link RuntimeHintsRegistrar} for Jakarta annotations and their pre-Jakarta equivalents.

View File

@@ -22,13 +22,14 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Executable;
import java.lang.reflect.Parameter;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.beans.factory.config.DependencyDescriptor;
import org.springframework.core.MethodParameter;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.SynthesizingMethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -46,8 +47,7 @@ public final class ParameterResolutionDelegate {
private static final AnnotatedElement EMPTY_ANNOTATED_ELEMENT = new AnnotatedElement() {
@Override
@Nullable
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
public <T extends Annotation> @Nullable T getAnnotation(Class<T> annotationClass) {
return null;
}
@Override
@@ -116,8 +116,7 @@ public final class ParameterResolutionDelegate {
* @see SynthesizingMethodParameter#forExecutable(Executable, int)
* @see AutowireCapableBeanFactory#resolveDependency(DependencyDescriptor, String)
*/
@Nullable
public static Object resolveDependency(
public static @Nullable Object resolveDependency(
Parameter parameter, int parameterIndex, Class<?> containingClass, AutowireCapableBeanFactory beanFactory)
throws BeansException {

View File

@@ -22,6 +22,8 @@ import java.lang.reflect.Method;
import java.util.Map;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.SimpleTypeConverter;
import org.springframework.beans.TypeConverter;
import org.springframework.beans.factory.BeanFactory;
@@ -36,7 +38,6 @@ import org.springframework.core.MethodParameter;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
@@ -172,8 +173,7 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
* {@code null} if no qualifier has been found at all
*/
@Nullable
protected Boolean checkQualifiers(BeanDefinitionHolder bdHolder, Annotation[] annotationsToSearch) {
protected @Nullable Boolean checkQualifiers(BeanDefinitionHolder bdHolder, Annotation[] annotationsToSearch) {
boolean qualifierFound = false;
if (!ObjectUtils.isEmpty(annotationsToSearch)) {
SimpleTypeConverter typeConverter = new SimpleTypeConverter();
@@ -327,14 +327,12 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
return true;
}
@Nullable
protected Annotation getQualifiedElementAnnotation(RootBeanDefinition bd, Class<? extends Annotation> type) {
protected @Nullable Annotation getQualifiedElementAnnotation(RootBeanDefinition bd, Class<? extends Annotation> type) {
AnnotatedElement qualifiedElement = bd.getQualifiedElement();
return (qualifiedElement != null ? AnnotationUtils.getAnnotation(qualifiedElement, type) : null);
}
@Nullable
protected Annotation getFactoryMethodAnnotation(RootBeanDefinition bd, Class<? extends Annotation> type) {
protected @Nullable Annotation getFactoryMethodAnnotation(RootBeanDefinition bd, Class<? extends Annotation> type) {
Method resolvedFactoryMethod = bd.getResolvedFactoryMethod();
return (resolvedFactoryMethod != null ? AnnotationUtils.getAnnotation(resolvedFactoryMethod, type) : null);
}
@@ -370,8 +368,7 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
}
@Override
@Nullable
public String getSuggestedName(DependencyDescriptor descriptor) {
public @Nullable String getSuggestedName(DependencyDescriptor descriptor) {
for (Annotation annotation : descriptor.getAnnotations()) {
if (isQualifier(annotation.annotationType())) {
Object value = AnnotationUtils.getValue(annotation);
@@ -388,8 +385,7 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
* @see Value
*/
@Override
@Nullable
public Object getSuggestedValue(DependencyDescriptor descriptor) {
public @Nullable Object getSuggestedValue(DependencyDescriptor descriptor) {
Object value = findValue(descriptor.getAnnotations());
if (value == null) {
MethodParameter methodParam = descriptor.getMethodParameter();
@@ -403,8 +399,7 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
/**
* Determine a suggested value from any of the given candidate annotations.
*/
@Nullable
protected Object findValue(Annotation[] annotationsToSearch) {
protected @Nullable Object findValue(Annotation[] annotationsToSearch) {
if (annotationsToSearch.length > 0) { // qualifier annotations have to be local
AnnotationAttributes attr = AnnotatedElementUtils.getMergedAnnotationAttributes(
AnnotatedElementUtils.forAnnotations(annotationsToSearch), this.valueAnnotationType);

View File

@@ -1,9 +1,7 @@
/**
* Support package for annotation-driven bean configuration.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.beans.factory.annotation;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -16,9 +16,10 @@
package org.springframework.beans.factory.aot;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.support.RegisteredBean;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.lang.Nullable;
/**
* Thrown when AOT fails to process a bean.

View File

@@ -16,7 +16,7 @@
package org.springframework.beans.factory.aot;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Abstract superclass for all exceptions thrown by ahead-of-time processing.

View File

@@ -16,7 +16,7 @@
package org.springframework.beans.factory.aot;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Throw when an AOT processor failed.

View File

@@ -25,13 +25,14 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -166,8 +167,7 @@ public final class AotServices<T> implements Iterable<T> {
* @param beanName the bean name
* @return the AOT service or {@code null}
*/
@Nullable
public T findByBeanName(String beanName) {
public @Nullable T findByBeanName(String beanName) {
return this.beans.get(beanName);
}
@@ -191,8 +191,7 @@ public final class AotServices<T> implements Iterable<T> {
private final SpringFactoriesLoader springFactoriesLoader;
@Nullable
private final ListableBeanFactory beanFactory;
private final @Nullable ListableBeanFactory beanFactory;
Loader(SpringFactoriesLoader springFactoriesLoader, @Nullable ListableBeanFactory beanFactory) {

View File

@@ -16,7 +16,8 @@
package org.springframework.beans.factory.aot;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -40,8 +41,7 @@ public interface AutowiredArguments {
* @return the argument
*/
@SuppressWarnings("unchecked")
@Nullable
default <T> T get(int index, Class<T> requiredType) {
default <T> @Nullable T get(int index, Class<T> requiredType) {
Object value = getObject(index);
if (!ClassUtils.isAssignableValue(requiredType, value)) {
throw new IllegalArgumentException("Argument type mismatch: expected '" +
@@ -57,8 +57,7 @@ public interface AutowiredArguments {
* @return the argument
*/
@SuppressWarnings("unchecked")
@Nullable
default <T> T get(int index) {
default <T> @Nullable T get(int index) {
return (T) getObject(index);
}
@@ -67,8 +66,7 @@ public interface AutowiredArguments {
* @param index the argument index
* @return the argument
*/
@Nullable
default Object getObject(int index) {
default @Nullable Object getObject(int index) {
return toArray()[index];
}

View File

@@ -20,6 +20,8 @@ import java.lang.reflect.Field;
import java.util.LinkedHashSet;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.hint.ExecutableMode;
import org.springframework.beans.BeansException;
import org.springframework.beans.TypeConverter;
@@ -29,7 +31,6 @@ import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.config.DependencyDescriptor;
import org.springframework.beans.factory.support.RegisteredBean;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.function.ThrowingConsumer;
@@ -57,8 +58,7 @@ public final class AutowiredFieldValueResolver extends AutowiredElementResolver
private final boolean required;
@Nullable
private final String shortcutBeanName;
private final @Nullable String shortcutBeanName;
private AutowiredFieldValueResolver(String fieldName, boolean required, @Nullable String shortcut) {
@@ -122,9 +122,8 @@ public final class AutowiredFieldValueResolver extends AutowiredElementResolver
* @param requiredType the required type
* @return the resolved field value
*/
@Nullable
@SuppressWarnings("unchecked")
public <T> T resolve(RegisteredBean registeredBean, Class<T> requiredType) {
public <T> @Nullable T resolve(RegisteredBean registeredBean, Class<T> requiredType) {
Object value = resolveObject(registeredBean);
Assert.isInstanceOf(requiredType, value);
return (T) value;
@@ -135,9 +134,8 @@ public final class AutowiredFieldValueResolver extends AutowiredElementResolver
* @param registeredBean the registered bean
* @return the resolved field value
*/
@Nullable
@SuppressWarnings("unchecked")
public <T> T resolve(RegisteredBean registeredBean) {
public <T> @Nullable T resolve(RegisteredBean registeredBean) {
return (T) resolveObject(registeredBean);
}
@@ -146,8 +144,7 @@ public final class AutowiredFieldValueResolver extends AutowiredElementResolver
* @param registeredBean the registered bean
* @return the resolved field value
*/
@Nullable
public Object resolveObject(RegisteredBean registeredBean) {
public @Nullable Object resolveObject(RegisteredBean registeredBean) {
Assert.notNull(registeredBean, "'registeredBean' must not be null");
return resolveValue(registeredBean, getField(registeredBean));
}
@@ -169,8 +166,7 @@ public final class AutowiredFieldValueResolver extends AutowiredElementResolver
}
}
@Nullable
private Object resolveValue(RegisteredBean registeredBean, Field field) {
private @Nullable Object resolveValue(RegisteredBean registeredBean, Field field) {
String beanName = registeredBean.getBeanName();
Class<?> beanClass = registeredBean.getBeanClass();
ConfigurableBeanFactory beanFactory = registeredBean.getBeanFactory();

View File

@@ -21,6 +21,8 @@ import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.hint.ExecutableMode;
import org.springframework.beans.BeansException;
import org.springframework.beans.TypeConverter;
@@ -31,7 +33,6 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory;
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.CollectionUtils;
import org.springframework.util.ReflectionUtils;
@@ -62,12 +63,11 @@ public final class AutowiredMethodArgumentsResolver extends AutowiredElementReso
private final boolean required;
@Nullable
private final String[] shortcutBeanNames;
private final String @Nullable [] shortcutBeanNames;
private AutowiredMethodArgumentsResolver(String methodName, Class<?>[] parameterTypes,
boolean required, @Nullable String[] shortcutBeanNames) {
boolean required, String @Nullable [] shortcutBeanNames) {
Assert.hasText(methodName, "'methodName' must not be empty");
this.methodName = methodName;
@@ -131,8 +131,7 @@ public final class AutowiredMethodArgumentsResolver extends AutowiredElementReso
* @param registeredBean the registered bean
* @return the resolved method arguments
*/
@Nullable
public AutowiredArguments resolve(RegisteredBean registeredBean) {
public @Nullable AutowiredArguments resolve(RegisteredBean registeredBean) {
Assert.notNull(registeredBean, "'registeredBean' must not be null");
return resolveArguments(registeredBean, getMethod(registeredBean));
}
@@ -154,8 +153,7 @@ public final class AutowiredMethodArgumentsResolver extends AutowiredElementReso
}
}
@Nullable
private AutowiredArguments resolveArguments(RegisteredBean registeredBean,
private @Nullable AutowiredArguments resolveArguments(RegisteredBean registeredBean,
Method method) {
String beanName = registeredBean.getBeanName();

View File

@@ -20,6 +20,8 @@ import java.util.List;
import javax.lang.model.element.Modifier;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.generate.GeneratedClass;
import org.springframework.aot.generate.GeneratedMethod;
import org.springframework.aot.generate.GeneratedMethods;
@@ -28,7 +30,6 @@ import org.springframework.aot.generate.MethodReference;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.RegisteredBean;
import org.springframework.javapoet.ClassName;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
@@ -46,8 +47,7 @@ class BeanDefinitionMethodGenerator {
private final RegisteredBean registeredBean;
@Nullable
private final String currentPropertyName;
private final @Nullable String currentPropertyName;
private final List<BeanRegistrationAotContribution> aotContributions;

View File

@@ -21,12 +21,12 @@ import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.aot.AotServices.Source;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.RegisteredBean;
import org.springframework.core.log.LogMessage;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -89,8 +89,7 @@ class BeanDefinitionMethodGeneratorFactory {
* @param currentPropertyName the property name that this bean belongs to
* @return a new {@link BeanDefinitionMethodGenerator} instance or {@code null}
*/
@Nullable
BeanDefinitionMethodGenerator getBeanDefinitionMethodGenerator(
@Nullable BeanDefinitionMethodGenerator getBeanDefinitionMethodGenerator(
RegisteredBean registeredBean, @Nullable String currentPropertyName) {
if (isExcluded(registeredBean)) {
@@ -110,8 +109,7 @@ class BeanDefinitionMethodGeneratorFactory {
* @param registeredBean the registered bean
* @return a new {@link BeanDefinitionMethodGenerator} instance or {@code null}
*/
@Nullable
BeanDefinitionMethodGenerator getBeanDefinitionMethodGenerator(RegisteredBean registeredBean) {
@Nullable BeanDefinitionMethodGenerator getBeanDefinitionMethodGenerator(RegisteredBean registeredBean) {
return getBeanDefinitionMethodGenerator(registeredBean, null);
}

View File

@@ -33,6 +33,8 @@ import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.Predicate;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.generate.GeneratedMethods;
import org.springframework.aot.generate.ValueCodeGenerator;
import org.springframework.aot.generate.ValueCodeGenerator.Delegate;
@@ -55,7 +57,6 @@ import org.springframework.beans.factory.support.InstanceSupplier;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.javapoet.CodeBlock;
import org.springframework.javapoet.CodeBlock.Builder;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.ReflectionUtils;
@@ -149,7 +150,7 @@ class BeanDefinitionPropertiesCodeGenerator {
}
private void addInitDestroyMethods(Builder code, AbstractBeanDefinition beanDefinition,
@Nullable String[] methodNames, String format) {
String @Nullable [] methodNames, String format) {
// For Publisher-based destroy methods
this.hints.reflection().registerType(TypeReference.of("org.reactivestreams.Publisher"));
@@ -395,8 +396,7 @@ class BeanDefinitionPropertiesCodeGenerator {
threadLocal.get().pop();
}
@Nullable
static String peek() {
static @Nullable String peek() {
String value = threadLocal.get().peek();
return ("".equals(value) ? null : value);
}

View File

@@ -22,6 +22,8 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.generate.GeneratedMethod;
import org.springframework.aot.generate.GeneratedMethods;
import org.springframework.aot.generate.ValueCodeGenerator;
@@ -37,7 +39,6 @@ import org.springframework.beans.factory.support.ManagedMap;
import org.springframework.beans.factory.support.ManagedSet;
import org.springframework.javapoet.AnnotationSpec;
import org.springframework.javapoet.CodeBlock;
import org.springframework.lang.Nullable;
/**
* Code generator {@link Delegate} for common bean definition property values.
@@ -102,8 +103,7 @@ abstract class BeanDefinitionPropertyValueCodeGeneratorDelegates {
private static final CodeBlock EMPTY_RESULT = CodeBlock.of("$T.ofEntries()", ManagedMap.class);
@Override
@Nullable
public CodeBlock generateCode(ValueCodeGenerator valueCodeGenerator, Object value) {
public @Nullable CodeBlock generateCode(ValueCodeGenerator valueCodeGenerator, Object value) {
if (value instanceof ManagedMap<?, ?> managedMap) {
return generateManagedMapCode(valueCodeGenerator, managedMap);
}
@@ -139,8 +139,7 @@ abstract class BeanDefinitionPropertyValueCodeGeneratorDelegates {
private static class LinkedHashMapDelegate extends MapDelegate {
@Override
@Nullable
protected CodeBlock generateMapCode(ValueCodeGenerator valueCodeGenerator, Map<?, ?> map) {
protected @Nullable CodeBlock generateMapCode(ValueCodeGenerator valueCodeGenerator, Map<?, ?> map) {
GeneratedMethods generatedMethods = valueCodeGenerator.getGeneratedMethods();
if (map instanceof LinkedHashMap<?, ?> && generatedMethods != null) {
return generateLinkedHashMapCode(valueCodeGenerator, generatedMethods, map);
@@ -175,8 +174,7 @@ abstract class BeanDefinitionPropertyValueCodeGeneratorDelegates {
private static class BeanReferenceDelegate implements Delegate {
@Override
@Nullable
public CodeBlock generateCode(ValueCodeGenerator valueCodeGenerator, Object value) {
public @Nullable CodeBlock generateCode(ValueCodeGenerator valueCodeGenerator, Object value) {
if (value instanceof RuntimeBeanReference runtimeBeanReference &&
runtimeBeanReference.getBeanType() != null) {
return CodeBlock.of("new $T($T.class)", RuntimeBeanReference.class,
@@ -197,8 +195,7 @@ abstract class BeanDefinitionPropertyValueCodeGeneratorDelegates {
private static class TypedStringValueDelegate implements Delegate {
@Override
@Nullable
public CodeBlock generateCode(ValueCodeGenerator valueCodeGenerator, Object value) {
public @Nullable CodeBlock generateCode(ValueCodeGenerator valueCodeGenerator, Object value) {
if (value instanceof TypedStringValue typedStringValue) {
return generateTypeStringValueCode(valueCodeGenerator, typedStringValue);
}

View File

@@ -16,9 +16,10 @@
package org.springframework.beans.factory.aot;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.lang.Nullable;
/**
* AOT processor that makes bean factory initialization contributions by
@@ -58,7 +59,6 @@ public interface BeanFactoryInitializationAotProcessor {
* @param beanFactory the bean factory to process
* @return a {@link BeanFactoryInitializationAotContribution} or {@code null}
*/
@Nullable
BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory);
@Nullable BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory);
}

View File

@@ -27,6 +27,8 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.hint.ExecutableMode;
import org.springframework.beans.BeanInstantiationException;
import org.springframework.beans.BeanUtils;
@@ -43,7 +45,6 @@ import org.springframework.beans.factory.support.RegisteredBean;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.support.SimpleInstantiationStrategy;
import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
@@ -85,20 +86,17 @@ public final class BeanInstanceSupplier<T> extends AutowiredElementResolver impl
private final ExecutableLookup lookup;
@Nullable
private final ThrowingFunction<RegisteredBean, T> generatorWithoutArguments;
private final @Nullable ThrowingFunction<RegisteredBean, T> generatorWithoutArguments;
@Nullable
private final ThrowingBiFunction<RegisteredBean, AutowiredArguments, T> generatorWithArguments;
private final @Nullable ThrowingBiFunction<RegisteredBean, AutowiredArguments, T> generatorWithArguments;
@Nullable
private final String[] shortcutBeanNames;
private final String @Nullable [] shortcutBeanNames;
private BeanInstanceSupplier(ExecutableLookup lookup,
@Nullable ThrowingFunction<RegisteredBean, T> generatorWithoutArguments,
@Nullable ThrowingBiFunction<RegisteredBean, AutowiredArguments, T> generatorWithArguments,
@Nullable String[] shortcutBeanNames) {
String @Nullable [] shortcutBeanNames) {
this.lookup = lookup;
this.generatorWithoutArguments = generatorWithoutArguments;
@@ -208,8 +206,7 @@ public final class BeanInstanceSupplier<T> extends AutowiredElementResolver impl
}
@Override
@Nullable
public Method getFactoryMethod() {
public @Nullable Method getFactoryMethod() {
// Cached factory method retrieval for qualifier introspection etc.
if (this.lookup instanceof FactoryMethodLookup factoryMethodLookup) {
return factoryMethodLookup.get();
@@ -217,8 +214,7 @@ public final class BeanInstanceSupplier<T> extends AutowiredElementResolver impl
return null;
}
@Nullable
private Method getFactoryMethodForGenerator() {
private @Nullable Method getFactoryMethodForGenerator() {
// Avoid unnecessary currentlyInvokedFactoryMethod exposure outside of full configuration classes.
if (this.lookup instanceof FactoryMethodLookup factoryMethodLookup &&
factoryMethodLookup.declaringClass.getName().contains(ClassUtils.CGLIB_CLASS_SEPARATOR)) {
@@ -328,8 +324,7 @@ public final class BeanInstanceSupplier<T> extends AutowiredElementResolver impl
return resolvedHolder;
}
@Nullable
private Object resolveAutowiredArgument(RegisteredBean registeredBean, DependencyDescriptor descriptor,
private @Nullable Object resolveAutowiredArgument(RegisteredBean registeredBean, DependencyDescriptor descriptor,
@Nullable ValueHolder argumentValue, Set<String> autowiredBeanNames) {
TypeConverter typeConverter = registeredBean.getBeanFactory().getTypeConverter();
@@ -426,8 +421,7 @@ public final class BeanInstanceSupplier<T> extends AutowiredElementResolver impl
private final Class<?>[] parameterTypes;
@Nullable
private volatile Method resolvedMethod;
private volatile @Nullable Method resolvedMethod;
FactoryMethodLookup(Class<?> declaringClass, String methodName, Class<?>[] parameterTypes) {
this.declaringClass = declaringClass;

View File

@@ -18,8 +18,9 @@ package org.springframework.beans.factory.aot;
import java.util.function.UnaryOperator;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.generate.GenerationContext;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -94,8 +95,7 @@ public interface BeanRegistrationAotContribution {
* they are both {@code null}.
* @since 6.1
*/
@Nullable
static BeanRegistrationAotContribution concat(@Nullable BeanRegistrationAotContribution a,
static @Nullable BeanRegistrationAotContribution concat(@Nullable BeanRegistrationAotContribution a,
@Nullable BeanRegistrationAotContribution b) {
if (a == null) {

View File

@@ -16,9 +16,10 @@
package org.springframework.beans.factory.aot;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.support.RegisteredBean;
import org.springframework.lang.Nullable;
/**
* AOT processor that makes bean registration contributions by processing
@@ -72,8 +73,7 @@ public interface BeanRegistrationAotProcessor {
* @param registeredBean the registered bean to process
* @return a {@link BeanRegistrationAotContribution} or {@code null}
*/
@Nullable
BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean);
@Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean);
/**
* Return if the bean instance associated with this processor should be

View File

@@ -19,10 +19,11 @@ package org.springframework.beans.factory.aot;
import java.util.ArrayList;
import java.util.List;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.aot.BeanRegistrationsAotContribution.Registration;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.RegisteredBean;
import org.springframework.lang.Nullable;
/**
* {@link BeanFactoryInitializationAotProcessor} that contributes code to
@@ -37,8 +38,7 @@ import org.springframework.lang.Nullable;
class BeanRegistrationsAotProcessor implements BeanFactoryInitializationAotProcessor {
@Override
@Nullable
public BeanRegistrationsAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) {
public @Nullable BeanRegistrationsAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) {
BeanDefinitionMethodGeneratorFactory beanDefinitionMethodGeneratorFactory =
new BeanDefinitionMethodGeneratorFactory(beanFactory);
List<Registration> registrations = new ArrayList<>();

View File

@@ -23,6 +23,8 @@ import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Stream;
import org.jspecify.annotations.Nullable;
import org.springframework.core.ResolvableType;
import org.springframework.javapoet.AnnotationSpec;
import org.springframework.javapoet.AnnotationSpec.Builder;
@@ -30,7 +32,6 @@ import org.springframework.javapoet.CodeBlock;
import org.springframework.javapoet.FieldSpec;
import org.springframework.javapoet.MethodSpec;
import org.springframework.javapoet.TypeSpec;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
/**

View File

@@ -22,6 +22,8 @@ import java.util.List;
import java.util.function.Predicate;
import java.util.function.Supplier;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.generate.AccessControl;
import org.springframework.aot.generate.GenerationContext;
import org.springframework.aot.generate.MethodReference;
@@ -40,7 +42,6 @@ import org.springframework.core.ResolvableType;
import org.springframework.javapoet.ClassName;
import org.springframework.javapoet.CodeBlock;
import org.springframework.javapoet.ParameterizedTypeName;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.function.SingletonSupplier;
@@ -176,8 +177,7 @@ class DefaultBeanRegistrationCodeFragments implements BeanRegistrationCodeFragme
.generateCode(beanDefinition);
}
@Nullable
protected CodeBlock generateValueCode(GenerationContext generationContext, String name, Object value) {
protected @Nullable CodeBlock generateValueCode(GenerationContext generationContext, String name, Object value) {
RegisteredBean innerRegisteredBean = getInnerRegisteredBean(value);
if (innerRegisteredBean != null) {
BeanDefinitionMethodGenerator methodGenerator = this.beanDefinitionMethodGeneratorFactory
@@ -190,8 +190,7 @@ class DefaultBeanRegistrationCodeFragments implements BeanRegistrationCodeFragme
return null;
}
@Nullable
private RegisteredBean getInnerRegisteredBean(Object value) {
private @Nullable RegisteredBean getInnerRegisteredBean(Object value) {
if (value instanceof BeanDefinitionHolder beanDefinitionHolder) {
return RegisteredBean.ofInnerBean(this.registeredBean, beanDefinitionHolder);
}

View File

@@ -29,6 +29,7 @@ import kotlin.jvm.JvmClassMappingKt;
import kotlin.reflect.KClass;
import kotlin.reflect.KFunction;
import kotlin.reflect.KParameter;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.generate.AccessControl;
import org.springframework.aot.generate.AccessControl.Visibility;
@@ -54,7 +55,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.ClassUtils;
import org.springframework.util.function.ThrowingSupplier;

View File

@@ -1,9 +1,7 @@
/**
* AOT support for bean factories.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.beans.factory.aot;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -23,6 +23,7 @@ import java.lang.reflect.Proxy;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.SimpleTypeConverter;
import org.springframework.beans.TypeConverter;
@@ -33,7 +34,6 @@ import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.FactoryBeanNotInitializedException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
@@ -68,19 +68,15 @@ public abstract class AbstractFactoryBean<T>
private boolean singleton = true;
@Nullable
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
@Nullable
private BeanFactory beanFactory;
private @Nullable BeanFactory beanFactory;
private boolean initialized = false;
@Nullable
private T singletonInstance;
private @Nullable T singletonInstance;
@Nullable
private T earlySingletonInstance;
private @Nullable T earlySingletonInstance;
/**
@@ -109,8 +105,7 @@ public abstract class AbstractFactoryBean<T>
/**
* Return the BeanFactory that this bean runs in.
*/
@Nullable
protected BeanFactory getBeanFactory() {
protected @Nullable BeanFactory getBeanFactory() {
return this.beanFactory;
}
@@ -184,8 +179,7 @@ public abstract class AbstractFactoryBean<T>
* @return the singleton instance that this FactoryBean holds
* @throws IllegalStateException if the singleton instance is not initialized
*/
@Nullable
private T getSingletonInstance() throws IllegalStateException {
private @Nullable T getSingletonInstance() throws IllegalStateException {
Assert.state(this.initialized, "Singleton instance not initialized yet");
return this.singletonInstance;
}
@@ -208,8 +202,7 @@ public abstract class AbstractFactoryBean<T>
* @see org.springframework.beans.factory.FactoryBean#getObjectType()
*/
@Override
@Nullable
public abstract Class<?> getObjectType();
public abstract @Nullable Class<?> getObjectType();
/**
* Template method that subclasses must override to construct
@@ -234,8 +227,7 @@ public abstract class AbstractFactoryBean<T>
* or {@code null} to indicate a FactoryBeanNotInitializedException
* @see org.springframework.beans.factory.FactoryBeanNotInitializedException
*/
@Nullable
protected Class<?>[] getEarlySingletonInterfaces() {
protected Class<?> @Nullable [] getEarlySingletonInterfaces() {
Class<?> type = getObjectType();
return (type != null && type.isInterface() ? new Class<?>[] {type} : null);
}

View File

@@ -18,12 +18,13 @@ package org.springframework.beans.factory.config;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.beans.TypeConverter;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
import org.springframework.lang.Nullable;
/**
* Extension of the {@link org.springframework.beans.factory.BeanFactory}
@@ -381,8 +382,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
* @since 2.5
* @see #resolveDependency(DependencyDescriptor, String, Set, TypeConverter)
*/
@Nullable
Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName) throws BeansException;
@Nullable Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName) throws BeansException;
/**
* Resolve the specified dependency against the beans defined in this factory.
@@ -398,8 +398,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
* @since 2.5
* @see DependencyDescriptor
*/
@Nullable
Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName,
@Nullable Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName,
@Nullable Set<String> autowiredBeanNames, @Nullable TypeConverter typeConverter) throws BeansException;
}

View File

@@ -18,7 +18,7 @@ package org.springframework.beans.factory.config;
import java.io.Serializable;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Simple marker class for an individually autowired property value, to be added

View File

@@ -16,11 +16,12 @@
package org.springframework.beans.factory.config;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanMetadataElement;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.core.AttributeAccessor;
import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable;
/**
* A BeanDefinition describes a bean instance, which has property values,
@@ -93,8 +94,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
/**
* Return the name of the parent definition of this bean definition, if any.
*/
@Nullable
String getParentName();
@Nullable String getParentName();
/**
* Specify the bean class name of this bean definition.
@@ -118,8 +118,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
* @see #getFactoryBeanName()
* @see #getFactoryMethodName()
*/
@Nullable
String getBeanClassName();
@Nullable String getBeanClassName();
/**
* Override the target scope of this bean, specifying a new scope name.
@@ -132,8 +131,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
* Return the name of the current target scope for this bean,
* or {@code null} if not known yet.
*/
@Nullable
String getScope();
@Nullable String getScope();
/**
* Set whether this bean should be lazily initialized.
@@ -155,13 +153,12 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
* constructor arguments. This property should just be necessary for other kinds
* of dependencies like statics (*ugh*) or database preparation on startup.
*/
void setDependsOn(@Nullable String... dependsOn);
void setDependsOn(String @Nullable ... dependsOn);
/**
* Return the bean names that this bean depends on.
*/
@Nullable
String[] getDependsOn();
String @Nullable [] getDependsOn();
/**
* Set whether this bean is a candidate for getting autowired into some other bean.
@@ -222,8 +219,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
* @see #getFactoryMethodName()
* @see #getBeanClassName()
*/
@Nullable
String getFactoryBeanName();
@Nullable String getFactoryBeanName();
/**
* Specify a factory method, if any. This method will be invoked with
@@ -240,8 +236,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
* @see #getFactoryBeanName()
* @see #getBeanClassName()
*/
@Nullable
String getFactoryMethodName();
@Nullable String getFactoryMethodName();
/**
* Return the constructor argument values for this bean.
@@ -285,8 +280,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
* Return the name of the initializer method.
* @since 5.1
*/
@Nullable
String getInitMethodName();
@Nullable String getInitMethodName();
/**
* Set the name of the destroy method.
@@ -298,8 +292,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
* Return the name of the destroy method.
* @since 5.1
*/
@Nullable
String getDestroyMethodName();
@Nullable String getDestroyMethodName();
/**
* Set the role hint for this {@code BeanDefinition}. The role hint
@@ -331,8 +324,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
/**
* Return a human-readable description of this bean definition.
*/
@Nullable
String getDescription();
@Nullable String getDescription();
// Read-only attributes
@@ -373,8 +365,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
* Return a description of the resource that this bean definition
* came from (for the purpose of showing context in case of errors).
*/
@Nullable
String getResourceDescription();
@Nullable String getResourceDescription();
/**
* Return the originating BeanDefinition, or {@code null} if none.
@@ -382,7 +373,6 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
* <p>Note that this method returns the immediate originator. Iterate through the
* originator chain to find the original BeanDefinition as defined by the user.
*/
@Nullable
BeanDefinition getOriginatingBeanDefinition();
@Nullable BeanDefinition getOriginatingBeanDefinition();
}

View File

@@ -16,9 +16,10 @@
package org.springframework.beans.factory.config;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanMetadataElement;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@@ -43,8 +44,7 @@ public class BeanDefinitionHolder implements BeanMetadataElement {
private final String beanName;
@Nullable
private final String[] aliases;
private final String @Nullable [] aliases;
/**
@@ -62,7 +62,7 @@ public class BeanDefinitionHolder implements BeanMetadataElement {
* @param beanName the name of the bean, as specified for the bean definition
* @param aliases alias names for the bean, or {@code null} if none
*/
public BeanDefinitionHolder(BeanDefinition beanDefinition, String beanName, @Nullable String[] aliases) {
public BeanDefinitionHolder(BeanDefinition beanDefinition, String beanName, String @Nullable [] aliases) {
Assert.notNull(beanDefinition, "BeanDefinition must not be null");
Assert.notNull(beanName, "Bean name must not be null");
this.beanDefinition = beanDefinition;
@@ -103,8 +103,7 @@ public class BeanDefinitionHolder implements BeanMetadataElement {
* Return the alias names for the bean, as specified directly for the bean definition.
* @return the array of alias names, or {@code null} if none
*/
@Nullable
public String[] getAliases() {
public String @Nullable [] getAliases() {
return this.aliases;
}
@@ -113,8 +112,7 @@ public class BeanDefinitionHolder implements BeanMetadataElement {
* @see BeanDefinition#getSource()
*/
@Override
@Nullable
public Object getSource() {
public @Nullable Object getSource() {
return this.beanDefinition.getSource();
}

View File

@@ -22,9 +22,10 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValue;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringValueResolver;
@@ -47,8 +48,7 @@ import org.springframework.util.StringValueResolver;
*/
public class BeanDefinitionVisitor {
@Nullable
private StringValueResolver valueResolver;
private @Nullable StringValueResolver valueResolver;
/**
@@ -170,8 +170,7 @@ public class BeanDefinitionVisitor {
}
@SuppressWarnings("rawtypes")
@Nullable
protected Object resolveValue(@Nullable Object value) {
protected @Nullable Object resolveValue(@Nullable Object value) {
if (value instanceof BeanDefinition beanDef) {
visitBeanDefinition(beanDef);
}
@@ -284,8 +283,7 @@ public class BeanDefinitionVisitor {
* @param strVal the original String value
* @return the resolved String value
*/
@Nullable
protected String resolveStringValue(String strVal) {
protected @Nullable String resolveStringValue(String strVal) {
if (this.valueResolver == null) {
throw new IllegalStateException("No StringValueResolver specified - pass a resolver " +
"object into the constructor or override the 'resolveStringValue' method");

View File

@@ -16,7 +16,8 @@
package org.springframework.beans.factory.config;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert;
/**
@@ -29,8 +30,7 @@ public class BeanExpressionContext {
private final ConfigurableBeanFactory beanFactory;
@Nullable
private final Scope scope;
private final @Nullable Scope scope;
public BeanExpressionContext(ConfigurableBeanFactory beanFactory, @Nullable Scope scope) {
@@ -43,8 +43,7 @@ public class BeanExpressionContext {
return this.beanFactory;
}
@Nullable
public final Scope getScope() {
public final @Nullable Scope getScope() {
return this.scope;
}
@@ -54,8 +53,7 @@ public class BeanExpressionContext {
(this.scope != null && this.scope.resolveContextualObject(key) != null));
}
@Nullable
public Object getObject(String key) {
public @Nullable Object getObject(String key) {
if (this.beanFactory.containsBean(key)) {
return this.beanFactory.getBean(key);
}

View File

@@ -16,8 +16,9 @@
package org.springframework.beans.factory.config;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.lang.Nullable;
/**
* Strategy interface for resolving a value by evaluating it as an expression,
@@ -42,7 +43,6 @@ public interface BeanExpressionResolver {
* @return the resolved value (potentially the given value as-is)
* @throws BeansException if evaluation failed
*/
@Nullable
Object evaluate(@Nullable String value, BeanExpressionContext beanExpressionContext) throws BeansException;
@Nullable Object evaluate(@Nullable String value, BeanExpressionContext beanExpressionContext) throws BeansException;
}

View File

@@ -16,8 +16,9 @@
package org.springframework.beans.factory.config;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.lang.Nullable;
/**
* Factory hook that allows for custom modification of new bean instances &mdash;
@@ -70,8 +71,7 @@ public interface BeanPostProcessor {
* @throws org.springframework.beans.BeansException in case of errors
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet
*/
@Nullable
default Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
default @Nullable Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
@@ -96,8 +96,7 @@ public interface BeanPostProcessor {
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet
* @see org.springframework.beans.factory.FactoryBean
*/
@Nullable
default Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
default @Nullable Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
return bean;
}

View File

@@ -19,6 +19,8 @@ package org.springframework.beans.factory.config;
import java.beans.PropertyEditor;
import java.util.concurrent.Executor;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.beans.PropertyEditorRegistry;
import org.springframework.beans.TypeConverter;
@@ -28,7 +30,6 @@ import org.springframework.beans.factory.HierarchicalBeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.metrics.ApplicationStartup;
import org.springframework.lang.Nullable;
import org.springframework.util.StringValueResolver;
/**
@@ -94,8 +95,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single
* (only {@code null} if even the system ClassLoader isn't accessible).
* @see org.springframework.util.ClassUtils#forName(String, ClassLoader)
*/
@Nullable
ClassLoader getBeanClassLoader();
@Nullable ClassLoader getBeanClassLoader();
/**
* Specify a temporary ClassLoader to use for type matching purposes.
@@ -113,8 +113,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single
* if any.
* @since 2.5
*/
@Nullable
ClassLoader getTempClassLoader();
@Nullable ClassLoader getTempClassLoader();
/**
* Set whether to cache bean metadata such as given bean definitions
@@ -144,8 +143,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single
* Return the resolution strategy for expressions in bean definition values.
* @since 3.0
*/
@Nullable
BeanExpressionResolver getBeanExpressionResolver();
@Nullable BeanExpressionResolver getBeanExpressionResolver();
/**
* Set the {@link Executor} (possibly a {@link org.springframework.core.task.TaskExecutor})
@@ -160,8 +158,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single
* for background bootstrapping, if any.
* @since 6.2
*/
@Nullable
Executor getBootstrapExecutor();
@Nullable Executor getBootstrapExecutor();
/**
* Specify a {@link ConversionService} to use for converting
@@ -174,8 +171,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single
* Return the associated ConversionService, if any.
* @since 3.0
*/
@Nullable
ConversionService getConversionService();
@Nullable ConversionService getConversionService();
/**
* Add a PropertyEditorRegistrar to be applied to all bean creation processes.
@@ -246,8 +242,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single
* @return the resolved value (may be the original value as-is)
* @since 3.0
*/
@Nullable
String resolveEmbeddedValue(String value);
@Nullable String resolveEmbeddedValue(String value);
/**
* Add a new BeanPostProcessor that will get applied to beans created
@@ -290,8 +285,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single
* @return the registered Scope implementation, or {@code null} if none
* @see #registerScope
*/
@Nullable
Scope getRegisteredScope(String scopeName);
@Nullable Scope getRegisteredScope(String scopeName);
/**
* Set the {@code ApplicationStartup} for this bean factory.

View File

@@ -18,10 +18,11 @@ package org.springframework.beans.factory.config;
import java.util.Iterator;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.lang.Nullable;
/**
* Configuration interface to be implemented by most listable bean factories.

View File

@@ -24,9 +24,10 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanMetadataElement;
import org.springframework.beans.Mergeable;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
@@ -144,8 +145,7 @@ public class ConstructorArgumentValues {
* untyped values only)
* @return the ValueHolder for the argument, or {@code null} if none set
*/
@Nullable
public ValueHolder getIndexedArgumentValue(int index, @Nullable Class<?> requiredType) {
public @Nullable ValueHolder getIndexedArgumentValue(int index, @Nullable Class<?> requiredType) {
return getIndexedArgumentValue(index, requiredType, null);
}
@@ -158,8 +158,7 @@ public class ConstructorArgumentValues {
* unnamed values only, or empty String to match any name)
* @return the ValueHolder for the argument, or {@code null} if none set
*/
@Nullable
public ValueHolder getIndexedArgumentValue(int index, @Nullable Class<?> requiredType, @Nullable String requiredName) {
public @Nullable ValueHolder getIndexedArgumentValue(int index, @Nullable Class<?> requiredType, @Nullable String requiredName) {
Assert.isTrue(index >= 0, "Index must not be negative");
ValueHolder valueHolder = this.indexedArgumentValues.get(index);
if (valueHolder != null &&
@@ -246,8 +245,7 @@ public class ConstructorArgumentValues {
* @param requiredType the type to match
* @return the ValueHolder for the argument, or {@code null} if none set
*/
@Nullable
public ValueHolder getGenericArgumentValue(Class<?> requiredType) {
public @Nullable ValueHolder getGenericArgumentValue(Class<?> requiredType) {
return getGenericArgumentValue(requiredType, null, null);
}
@@ -257,8 +255,7 @@ public class ConstructorArgumentValues {
* @param requiredName the name to match
* @return the ValueHolder for the argument, or {@code null} if none set
*/
@Nullable
public ValueHolder getGenericArgumentValue(Class<?> requiredType, String requiredName) {
public @Nullable ValueHolder getGenericArgumentValue(Class<?> requiredType, String requiredName) {
return getGenericArgumentValue(requiredType, requiredName, null);
}
@@ -274,8 +271,7 @@ public class ConstructorArgumentValues {
* in the current resolution process and should therefore not be returned again
* @return the ValueHolder for the argument, or {@code null} if none found
*/
@Nullable
public ValueHolder getGenericArgumentValue(@Nullable Class<?> requiredType, @Nullable String requiredName,
public @Nullable ValueHolder getGenericArgumentValue(@Nullable Class<?> requiredType, @Nullable String requiredName,
@Nullable Set<ValueHolder> usedValueHolders) {
for (ValueHolder valueHolder : this.genericArgumentValues) {
@@ -316,8 +312,7 @@ public class ConstructorArgumentValues {
* @param requiredType the parameter type to match
* @return the ValueHolder for the argument, or {@code null} if none set
*/
@Nullable
public ValueHolder getArgumentValue(int index, Class<?> requiredType) {
public @Nullable ValueHolder getArgumentValue(int index, Class<?> requiredType) {
return getArgumentValue(index, requiredType, null, null);
}
@@ -329,8 +324,7 @@ public class ConstructorArgumentValues {
* @param requiredName the parameter name to match
* @return the ValueHolder for the argument, or {@code null} if none set
*/
@Nullable
public ValueHolder getArgumentValue(int index, Class<?> requiredType, String requiredName) {
public @Nullable ValueHolder getArgumentValue(int index, Class<?> requiredType, String requiredName) {
return getArgumentValue(index, requiredType, requiredName, null);
}
@@ -348,8 +342,7 @@ public class ConstructorArgumentValues {
* in case of multiple generic argument values of the same type)
* @return the ValueHolder for the argument, or {@code null} if none set
*/
@Nullable
public ValueHolder getArgumentValue(int index, @Nullable Class<?> requiredType,
public @Nullable ValueHolder getArgumentValue(int index, @Nullable Class<?> requiredType,
@Nullable String requiredName, @Nullable Set<ValueHolder> usedValueHolders) {
Assert.isTrue(index >= 0, "Index must not be negative");
@@ -455,22 +448,17 @@ public class ConstructorArgumentValues {
*/
public static class ValueHolder implements BeanMetadataElement {
@Nullable
private Object value;
private @Nullable Object value;
@Nullable
private String type;
private @Nullable String type;
@Nullable
private String name;
private @Nullable String name;
@Nullable
private Object source;
private @Nullable Object source;
private boolean converted = false;
@Nullable
private Object convertedValue;
private @Nullable Object convertedValue;
/**
* Create a new ValueHolder for the given value.
@@ -512,8 +500,7 @@ public class ConstructorArgumentValues {
/**
* Return the value for the constructor argument.
*/
@Nullable
public Object getValue() {
public @Nullable Object getValue() {
return this.value;
}
@@ -527,8 +514,7 @@ public class ConstructorArgumentValues {
/**
* Return the type of the constructor argument.
*/
@Nullable
public String getType() {
public @Nullable String getType() {
return this.type;
}
@@ -542,8 +528,7 @@ public class ConstructorArgumentValues {
/**
* Return the name of the constructor argument.
*/
@Nullable
public String getName() {
public @Nullable String getName() {
return this.name;
}
@@ -556,8 +541,7 @@ public class ConstructorArgumentValues {
}
@Override
@Nullable
public Object getSource() {
public @Nullable Object getSource() {
return this.source;
}
@@ -582,8 +566,7 @@ public class ConstructorArgumentValues {
* Return the converted value of the constructor argument,
* after processed type conversion.
*/
@Nullable
public synchronized Object getConvertedValue() {
public synchronized @Nullable Object getConvertedValue() {
return this.convertedValue;
}

View File

@@ -21,11 +21,11 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.core.Ordered;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
/**
@@ -99,11 +99,9 @@ public class CustomEditorConfigurer implements BeanFactoryPostProcessor, Ordered
private int order = Ordered.LOWEST_PRECEDENCE; // default: same as non-Ordered
@Nullable
private PropertyEditorRegistrar[] propertyEditorRegistrars;
private PropertyEditorRegistrar @Nullable [] propertyEditorRegistrars;
@Nullable
private Map<Class<?>, Class<? extends PropertyEditor>> customEditors;
private @Nullable Map<Class<?>, Class<? extends PropertyEditor>> customEditors;
public void setOrder(int order) {

View File

@@ -19,11 +19,12 @@ package org.springframework.beans.factory.config;
import java.util.LinkedHashMap;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.core.Ordered;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -46,13 +47,11 @@ import org.springframework.util.ClassUtils;
*/
public class CustomScopeConfigurer implements BeanFactoryPostProcessor, BeanClassLoaderAware, Ordered {
@Nullable
private Map<String, Object> scopes;
private @Nullable Map<String, Object> scopes;
private int order = Ordered.LOWEST_PRECEDENCE;
@Nullable
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
/**

View File

@@ -26,6 +26,7 @@ import java.util.Optional;
import kotlin.reflect.KProperty;
import kotlin.reflect.jvm.ReflectJvmMapping;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
@@ -36,7 +37,6 @@ import org.springframework.core.MethodParameter;
import org.springframework.core.ParameterNameDiscoverer;
import org.springframework.core.ResolvableType;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
/**
@@ -52,16 +52,13 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
private final Class<?> declaringClass;
@Nullable
private String methodName;
private @Nullable String methodName;
@Nullable
private Class<?>[] parameterTypes;
private Class<?> @Nullable [] parameterTypes;
private int parameterIndex;
@Nullable
private String fieldName;
private @Nullable String fieldName;
private final boolean required;
@@ -69,14 +66,11 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
private int nestingLevel = 1;
@Nullable
private Class<?> containingClass;
private @Nullable Class<?> containingClass;
@Nullable
private transient volatile ResolvableType resolvableType;
private transient volatile @Nullable ResolvableType resolvableType;
@Nullable
private transient volatile TypeDescriptor typeDescriptor;
private transient volatile @Nullable TypeDescriptor typeDescriptor;
/**
@@ -213,8 +207,7 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
* @throws BeansException in case of the not-unique scenario being fatal
* @since 5.1
*/
@Nullable
public Object resolveNotUnique(ResolvableType type, Map<String, Object> matchingBeans) throws BeansException {
public @Nullable Object resolveNotUnique(ResolvableType type, Map<String, Object> matchingBeans) throws BeansException {
throw new NoUniqueBeanDefinitionException(type, matchingBeans.keySet());
}
@@ -230,8 +223,7 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
* @throws BeansException if the shortcut could not be obtained
* @since 4.3.1
*/
@Nullable
public Object resolveShortcut(BeanFactory beanFactory) throws BeansException {
public @Nullable Object resolveShortcut(BeanFactory beanFactory) throws BeansException {
return null;
}
@@ -355,8 +347,7 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable
* Determine the name of the wrapped parameter/field.
* @return the declared name (may be {@code null} if unresolvable)
*/
@Nullable
public String getDependencyName() {
public @Nullable String getDependencyName() {
return (this.field != null ? this.field.getName() : obtainMethodParameter().getParameterName());
}

View File

@@ -16,7 +16,8 @@
package org.springframework.beans.factory.config;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.util.StringValueResolver;
/**
@@ -38,8 +39,7 @@ public class EmbeddedValueResolver implements StringValueResolver {
private final BeanExpressionContext exprContext;
@Nullable
private final BeanExpressionResolver exprResolver;
private final @Nullable BeanExpressionResolver exprResolver;
public EmbeddedValueResolver(ConfigurableBeanFactory beanFactory) {
@@ -49,8 +49,7 @@ public class EmbeddedValueResolver implements StringValueResolver {
@Override
@Nullable
public String resolveStringValue(String strVal) {
public @Nullable String resolveStringValue(String strVal) {
String value = this.exprContext.getBeanFactory().resolveEmbeddedValue(strVal);
if (this.exprResolver != null && value != null) {
Object evaluated = this.exprResolver.evaluate(value, this.exprContext);

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