Browse Source

Specify generic type nullness in spring-beans

See gh-34140
pull/34266/head
Sébastien Deleuze 1 year ago
parent
commit
928a3c7184
  1. 9
      spring-beans/src/main/java/org/springframework/beans/BeanUtils.java
  2. 12
      spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java
  3. 4
      spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java
  4. 6
      spring-beans/src/main/java/org/springframework/beans/factory/aot/AutowiredArguments.java
  5. 4
      spring-beans/src/main/java/org/springframework/beans/factory/aot/AutowiredMethodArgumentsResolver.java
  6. 12
      spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGenerator.java
  7. 8
      spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanInstanceSupplier.java
  8. 4
      spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java
  9. 4
      spring-beans/src/main/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBean.java
  10. 6
      spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
  11. 4
      spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java
  12. 4
      spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionValueResolver.java
  13. 6
      spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java
  14. 10
      spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java
  15. 3
      spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractBeanDefinitionParser.java
  16. 4
      spring-beans/src/main/java/org/springframework/beans/propertyeditors/StringArrayPropertyEditor.java
  17. 9
      spring-beans/src/main/java/org/springframework/beans/support/ArgumentConvertingMethodInvoker.java

9
spring-beans/src/main/java/org/springframework/beans/BeanUtils.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -196,7 +196,7 @@ public abstract class BeanUtils { @@ -196,7 +196,7 @@ public abstract class BeanUtils {
return ctor.newInstance();
}
Class<?>[] parameterTypes = ctor.getParameterTypes();
Object[] argsWithDefaultValues = new Object[args.length];
@Nullable Object[] argsWithDefaultValues = new Object[args.length];
for (int i = 0 ; i < args.length; i++) {
if (args[i] == null) {
Class<?> parameterType = parameterTypes[i];
@ -654,9 +654,10 @@ public abstract class BeanUtils { @@ -654,9 +654,10 @@ public abstract class BeanUtils {
* @see ConstructorProperties
* @see DefaultParameterNameDiscoverer
*/
public static String[] getParameterNames(Constructor<?> ctor) {
@SuppressWarnings("NullAway") // Dataflow analysis limitation
public static @Nullable String[] getParameterNames(Constructor<?> ctor) {
ConstructorProperties cp = ctor.getAnnotation(ConstructorProperties.class);
String[] paramNames = (cp != null ? cp.value() : parameterNameDiscoverer.getParameterNames(ctor));
@Nullable String[] paramNames = (cp != null ? cp.value() : parameterNameDiscoverer.getParameterNames(ctor));
Assert.state(paramNames != null, () -> "Cannot resolve parameter names for constructor " + ctor);
Assert.state(paramNames.length == ctor.getParameterCount(),
() -> "Invalid number of parameter names: " + paramNames.length + " for constructor " + ctor);

12
spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -812,7 +812,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA @@ -812,7 +812,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA
return;
}
Method method = (Method) this.member;
Object[] arguments;
@Nullable Object[] arguments;
if (this.cached) {
try {
arguments = resolveCachedArguments(beanName, this.cachedMethodArguments);
@ -838,20 +838,20 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA @@ -838,20 +838,20 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA
}
}
private Object @Nullable [] resolveCachedArguments(@Nullable String beanName, Object @Nullable [] cachedMethodArguments) {
private @Nullable Object @Nullable [] resolveCachedArguments(@Nullable String beanName, Object @Nullable [] cachedMethodArguments) {
if (cachedMethodArguments == null) {
return null;
}
Object[] arguments = new Object[cachedMethodArguments.length];
@Nullable Object[] arguments = new Object[cachedMethodArguments.length];
for (int i = 0; i < arguments.length; i++) {
arguments[i] = resolveCachedArgument(beanName, cachedMethodArguments[i]);
}
return arguments;
}
private Object @Nullable [] resolveMethodArguments(Method method, Object bean, @Nullable String beanName) {
private @Nullable Object @Nullable [] resolveMethodArguments(Method method, Object bean, @Nullable String beanName) {
int argumentCount = method.getParameterCount();
Object[] arguments = new Object[argumentCount];
@Nullable Object[] arguments = new Object[argumentCount];
DependencyDescriptor[] descriptors = new DependencyDescriptor[argumentCount];
Set<String> autowiredBeanNames = CollectionUtils.newLinkedHashSet(argumentCount);
Assert.state(beanFactory != null, "No BeanFactory available");

4
spring-beans/src/main/java/org/springframework/beans/factory/annotation/QualifierAnnotationAutowireCandidateResolver.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -291,7 +291,7 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa @@ -291,7 +291,7 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
}
}
Map<String, Object> attributes = AnnotationUtils.getAnnotationAttributes(annotation);
Map<String, @Nullable Object> attributes = AnnotationUtils.getAnnotationAttributes(annotation);
if (attributes.isEmpty() && qualifier == null) {
// If no attributes, the qualifier must be present
return false;

6
spring-beans/src/main/java/org/springframework/beans/factory/aot/AutowiredArguments.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -74,7 +74,7 @@ public interface AutowiredArguments { @@ -74,7 +74,7 @@ public interface AutowiredArguments {
* Return the arguments as an object array.
* @return the arguments as an object array
*/
Object[] toArray();
@Nullable Object[] toArray();
/**
* Factory method to create a new {@link AutowiredArguments} instance from
@ -82,7 +82,7 @@ public interface AutowiredArguments { @@ -82,7 +82,7 @@ public interface AutowiredArguments {
* @param arguments the arguments
* @return a new {@link AutowiredArguments} instance
*/
static AutowiredArguments of(Object[] arguments) {
static AutowiredArguments of(@Nullable Object[] arguments) {
Assert.notNull(arguments, "'arguments' must not be null");
return () -> arguments;
}

4
spring-beans/src/main/java/org/springframework/beans/factory/aot/AutowiredMethodArgumentsResolver.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -162,7 +162,7 @@ public final class AutowiredMethodArgumentsResolver extends AutowiredElementReso @@ -162,7 +162,7 @@ public final class AutowiredMethodArgumentsResolver extends AutowiredElementReso
Assert.isInstanceOf(AutowireCapableBeanFactory.class, beanFactory);
AutowireCapableBeanFactory autowireCapableBeanFactory = (AutowireCapableBeanFactory) beanFactory;
int argumentCount = method.getParameterCount();
Object[] arguments = new Object[argumentCount];
@Nullable Object[] arguments = new Object[argumentCount];
Set<String> autowiredBeanNames = CollectionUtils.newLinkedHashSet(argumentCount);
TypeConverter typeConverter = beanFactory.getTypeConverter();
for (int i = 0; i < argumentCount; i++) {

12
spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGenerator.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -111,7 +111,7 @@ class BeanDefinitionPropertiesCodeGenerator { @@ -111,7 +111,7 @@ class BeanDefinitionPropertiesCodeGenerator {
this.valueCodeGenerator = ValueCodeGenerator.with(allDelegates).scoped(generatedMethods);
}
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1128
CodeBlock generateCode(RootBeanDefinition beanDefinition) {
CodeBlock.Builder code = CodeBlock.builder();
addStatementForValue(code, beanDefinition, BeanDefinition::getScope,
@ -344,7 +344,7 @@ class BeanDefinitionPropertiesCodeGenerator { @@ -344,7 +344,7 @@ class BeanDefinitionPropertiesCodeGenerator {
}
private <B extends BeanDefinition, T> void addStatementForValue(
CodeBlock.Builder code, BeanDefinition beanDefinition, Function<B, T> getter, String format) {
CodeBlock.Builder code, BeanDefinition beanDefinition, Function<B, @Nullable T> getter, String format) {
addStatementForValue(code, beanDefinition, getter,
(defaultValue, actualValue) -> !Objects.equals(defaultValue, actualValue), format);
@ -352,14 +352,14 @@ class BeanDefinitionPropertiesCodeGenerator { @@ -352,14 +352,14 @@ class BeanDefinitionPropertiesCodeGenerator {
private <B extends BeanDefinition, T> void addStatementForValue(
CodeBlock.Builder code, BeanDefinition beanDefinition,
Function<B, T> getter, BiPredicate<T, T> filter, String format) {
Function<B, @Nullable T> getter, BiPredicate<T, T> filter, String format) {
addStatementForValue(code, beanDefinition, getter, filter, format, actualValue -> actualValue);
}
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "NullAway"})
private <B extends BeanDefinition, T> void addStatementForValue(
CodeBlock.Builder code, BeanDefinition beanDefinition, Function<B, T> getter,
CodeBlock.Builder code, BeanDefinition beanDefinition, Function<B, @Nullable T> getter,
BiPredicate<T, T> filter, String format, Function<T, Object> formatter) {
T defaultValue = getter.apply((B) DEFAULT_BEAN_DEFINITION);

8
spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanInstanceSupplier.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -200,7 +200,7 @@ public final class BeanInstanceSupplier<T> extends AutowiredElementResolver impl @@ -200,7 +200,7 @@ public final class BeanInstanceSupplier<T> extends AutowiredElementResolver impl
}
else {
Executable executable = this.lookup.get(registeredBean);
Object[] arguments = resolveArguments(registeredBean, executable).toArray();
@Nullable Object[] arguments = resolveArguments(registeredBean, executable).toArray();
return invokeBeanSupplier(executable, () -> (T) instantiate(registeredBean, executable, arguments));
}
}
@ -242,7 +242,7 @@ public final class BeanInstanceSupplier<T> extends AutowiredElementResolver impl @@ -242,7 +242,7 @@ public final class BeanInstanceSupplier<T> extends AutowiredElementResolver impl
private AutowiredArguments resolveArguments(RegisteredBean registeredBean, Executable executable) {
int parameterCount = executable.getParameterCount();
Object[] resolved = new Object[parameterCount];
@Nullable Object[] resolved = new Object[parameterCount];
Assert.isTrue(this.shortcutBeanNames == null || this.shortcutBeanNames.length == resolved.length,
() -> "'shortcuts' must contain " + resolved.length + " elements");
@ -341,7 +341,7 @@ public final class BeanInstanceSupplier<T> extends AutowiredElementResolver impl @@ -341,7 +341,7 @@ public final class BeanInstanceSupplier<T> extends AutowiredElementResolver impl
}
}
private Object instantiate(RegisteredBean registeredBean, Executable executable, Object[] args) {
private Object instantiate(RegisteredBean registeredBean, Executable executable, @Nullable Object[] args) {
if (executable instanceof Constructor<?> constructor) {
return BeanUtils.instantiateClass(constructor, args);
}

4
spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -220,7 +220,7 @@ public class BeanDefinitionVisitor { @@ -220,7 +220,7 @@ public class BeanDefinitionVisitor {
return value;
}
protected void visitArray(Object[] arrayVal) {
protected void visitArray(@Nullable Object[] arrayVal) {
for (int i = 0; i < arrayVal.length; i++) {
Object elem = arrayVal[i];
Object newVal = resolveValue(elem);

4
spring-beans/src/main/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBean.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -311,7 +311,7 @@ public class ServiceLocatorFactoryBean implements FactoryBean<Object>, BeanFacto @@ -311,7 +311,7 @@ public class ServiceLocatorFactoryBean implements FactoryBean<Object>, BeanFacto
*/
protected Exception createServiceLocatorException(Constructor<Exception> exceptionConstructor, BeansException cause) {
Class<?>[] paramTypes = exceptionConstructor.getParameterTypes();
Object[] args = new Object[paramTypes.length];
@Nullable Object[] args = new Object[paramTypes.length];
for (int i = 0; i < paramTypes.length; i++) {
if (String.class == paramTypes[i]) {
args[i] = cause.getMessage();

6
spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java

@ -548,7 +548,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac @@ -548,7 +548,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
* @see #instantiateUsingFactoryMethod
* @see #autowireConstructor
*/
protected Object doCreateBean(String beanName, RootBeanDefinition mbd, Object @Nullable [] args)
protected Object doCreateBean(String beanName, RootBeanDefinition mbd, @Nullable Object @Nullable [] args)
throws BeanCreationException {
// Instantiate the bean.
@ -753,7 +753,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac @@ -753,7 +753,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
// Fully resolve parameter names and argument values.
ConstructorArgumentValues cav = mbd.getConstructorArgumentValues();
Class<?>[] paramTypes = candidate.getParameterTypes();
String[] paramNames = null;
@Nullable String[] paramNames = null;
if (cav.containsNamedArgument()) {
ParameterNameDiscoverer pnd = getParameterNameDiscoverer();
if (pnd != null) {
@ -761,7 +761,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac @@ -761,7 +761,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
}
}
Set<ConstructorArgumentValues.ValueHolder> usedValueHolders = CollectionUtils.newHashSet(paramTypes.length);
Object[] args = new Object[paramTypes.length];
@Nullable Object[] args = new Object[paramTypes.length];
for (int i = 0; i < args.length; i++) {
ConstructorArgumentValues.ValueHolder valueHolder = cav.getArgumentValue(
i, paramTypes[i], (paramNames != null ? paramNames[i] : null), usedValueHolders);

4
spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -173,7 +173,7 @@ abstract class AutowireUtils { @@ -173,7 +173,7 @@ abstract class AutowireUtils {
* @since 3.2.5
*/
public static Class<?> resolveReturnTypeForFactoryMethod(
Method method, Object[] args, @Nullable ClassLoader classLoader) {
Method method, @Nullable Object[] args, @Nullable ClassLoader classLoader) {
Assert.notNull(method, "Method must not be null");
Assert.notNull(args, "Argument array must not be null");

4
spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionValueResolver.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -287,7 +287,7 @@ public class BeanDefinitionValueResolver { @@ -287,7 +287,7 @@ public class BeanDefinitionValueResolver {
}
else if (value instanceof String[] values) {
boolean actuallyResolved = false;
Object[] resolvedValues = new Object[values.length];
@Nullable Object[] resolvedValues = new Object[values.length];
for (int i = 0; i < values.length; i++) {
String originalValue = values[i];
Object resolvedValue = doEvaluate(originalValue);

6
spring-beans/src/main/java/org/springframework/beans/factory/support/ConstructorResolver.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -814,7 +814,7 @@ class ConstructorResolver { @@ -814,7 +814,7 @@ class ConstructorResolver {
/**
* Resolve the prepared arguments stored in the given bean definition.
*/
private Object[] resolvePreparedArguments(String beanName, RootBeanDefinition mbd, BeanWrapper bw,
private @Nullable Object[] resolvePreparedArguments(String beanName, RootBeanDefinition mbd, BeanWrapper bw,
Executable executable, Object[] argsToResolve) {
TypeConverter customConverter = this.beanFactory.getCustomTypeConverter();
@ -823,7 +823,7 @@ class ConstructorResolver { @@ -823,7 +823,7 @@ class ConstructorResolver {
new BeanDefinitionValueResolver(this.beanFactory, beanName, mbd, converter);
Class<?>[] paramTypes = executable.getParameterTypes();
Object[] resolvedArgs = new Object[argsToResolve.length];
@Nullable Object[] resolvedArgs = new Object[argsToResolve.length];
for (int argIndex = 0; argIndex < argsToResolve.length; argIndex++) {
Object argValue = argsToResolve[argIndex];
Class<?> paramType = paramTypes[argIndex];

10
spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -357,7 +357,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto @@ -357,7 +357,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@SuppressWarnings("unchecked")
@Override
public <T> T getBean(Class<T> requiredType, Object @Nullable ... args) throws BeansException {
public <T> T getBean(Class<T> requiredType, @Nullable Object @Nullable ... args) throws BeansException {
Assert.notNull(requiredType, "Required type must not be null");
Object resolved = resolveBean(ResolvableType.forRawClass(requiredType), args, false);
if (resolved == null) {
@ -500,7 +500,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto @@ -500,7 +500,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
};
}
private <T> @Nullable T resolveBean(ResolvableType requiredType, Object @Nullable [] args, boolean nonUniqueAsNull) {
private <T> @Nullable T resolveBean(ResolvableType requiredType, @Nullable Object @Nullable [] args, boolean nonUniqueAsNull) {
NamedBeanHolder<T> namedBean = resolveNamedBean(requiredType, args, nonUniqueAsNull);
if (namedBean != null) {
return namedBean.getBeanInstance();
@ -1411,7 +1411,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto @@ -1411,7 +1411,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
@SuppressWarnings("unchecked")
private <T> @Nullable NamedBeanHolder<T> resolveNamedBean(
ResolvableType requiredType, Object @Nullable [] args, boolean nonUniqueAsNull) throws BeansException {
ResolvableType requiredType, @Nullable Object @Nullable [] args, boolean nonUniqueAsNull) throws BeansException {
Assert.notNull(requiredType, "Required type must not be null");
String[] candidateNames = getBeanNamesForType(requiredType);
@ -1465,7 +1465,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto @@ -1465,7 +1465,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
}
private <T> @Nullable NamedBeanHolder<T> resolveNamedBean(
String beanName, ResolvableType requiredType, Object @Nullable [] args) throws BeansException {
String beanName, ResolvableType requiredType, @Nullable Object @Nullable [] args) throws BeansException {
Object bean = getBean(beanName, null, args);
if (bean instanceof NullBean) {

3
spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractBeanDefinitionParser.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -58,6 +58,7 @@ public abstract class AbstractBeanDefinitionParser implements BeanDefinitionPars @@ -58,6 +58,7 @@ public abstract class AbstractBeanDefinitionParser implements BeanDefinitionPars
@Override
@SuppressWarnings("NullAway") // Dataflow analysis limitation
public final @Nullable BeanDefinition parse(Element element, ParserContext parserContext) {
AbstractBeanDefinition definition = parseInternal(element, parserContext);
if (definition != null && !parserContext.isNested()) {

4
spring-beans/src/main/java/org/springframework/beans/propertyeditors/StringArrayPropertyEditor.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -127,7 +127,7 @@ public class StringArrayPropertyEditor extends PropertyEditorSupport { @@ -127,7 +127,7 @@ public class StringArrayPropertyEditor extends PropertyEditorSupport {
@Override
public void setAsText(String text) throws IllegalArgumentException {
String[] array = StringUtils.delimitedListToStringArray(text, this.separator, this.charsToDelete);
@Nullable String[] array = StringUtils.delimitedListToStringArray(text, this.separator, this.charsToDelete);
if (this.emptyArrayAsNull && array.length == 0) {
setValue(null);
}

9
spring-beans/src/main/java/org/springframework/beans/support/ArgumentConvertingMethodInvoker.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -130,7 +130,8 @@ public class ArgumentConvertingMethodInvoker extends MethodInvoker { @@ -130,7 +130,8 @@ public class ArgumentConvertingMethodInvoker extends MethodInvoker {
* @param arguments the argument values to match against method parameters
* @return a matching method, or {@code null} if none
*/
protected @Nullable Method doFindMatchingMethod(Object[] arguments) {
@SuppressWarnings("NullAway") // Dataflow analysis limitation
protected @Nullable Method doFindMatchingMethod(@Nullable Object[] arguments) {
TypeConverter converter = getTypeConverter();
if (converter != null) {
String targetMethod = getTargetMethod();
@ -140,14 +141,14 @@ public class ArgumentConvertingMethodInvoker extends MethodInvoker { @@ -140,14 +141,14 @@ public class ArgumentConvertingMethodInvoker extends MethodInvoker {
Assert.state(targetClass != null, "No target class set");
Method[] candidates = ReflectionUtils.getAllDeclaredMethods(targetClass);
int minTypeDiffWeight = Integer.MAX_VALUE;
Object[] argumentsToUse = null;
@Nullable Object[] argumentsToUse = null;
for (Method candidate : candidates) {
if (candidate.getName().equals(targetMethod)) {
// Check if the inspected method has the correct number of parameters.
int parameterCount = candidate.getParameterCount();
if (parameterCount == argCount) {
Class<?>[] paramTypes = candidate.getParameterTypes();
Object[] convertedArguments = new Object[argCount];
@Nullable Object[] convertedArguments = new Object[argCount];
boolean match = true;
for (int j = 0; j < argCount && match; j++) {
// Verify that the supplied argument is assignable to the method parameter.

Loading…
Cancel
Save