Skip to content

Commit 7f21443

Browse files
committed
Refine null-safety based on IDEA warnings
See gh-28797
1 parent 4189f8b commit 7f21443

File tree

22 files changed

+61
-47
lines changed

22 files changed

+61
-47
lines changed

spring-aop/src/main/java/org/springframework/aop/MethodMatcher.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.lang.reflect.Method;
2020

21+
import org.jspecify.annotations.Nullable;
22+
2123
/**
2224
* Part of a {@link Pointcut}: Checks whether the target method is eligible for advice.
2325
*
@@ -94,7 +96,7 @@ public interface MethodMatcher {
9496
* @return whether there's a runtime match
9597
* @see #matches(Method, Class)
9698
*/
97-
boolean matches(Method method, Class<?> targetClass, Object... args);
99+
boolean matches(Method method, Class<?> targetClass, @Nullable Object... args);
98100

99101

100102
/**

spring-aop/src/main/java/org/springframework/aop/TrueMethodMatcher.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.io.Serializable;
2020
import java.lang.reflect.Method;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
/**
2325
* Canonical MethodMatcher instance that matches all methods.
2426
*
@@ -48,7 +50,7 @@ public boolean matches(Method method, Class<?> targetClass) {
4850
}
4951

5052
@Override
51-
public boolean matches(Method method, Class<?> targetClass, Object... args) {
53+
public boolean matches(Method method, Class<?> targetClass, @Nullable Object... args) {
5254
// Should never be invoked as isRuntime returns false.
5355
throw new UnsupportedOperationException();
5456
}

spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public boolean isRuntime() {
340340
}
341341

342342
@Override
343-
public boolean matches(Method method, Class<?> targetClass, Object... args) {
343+
public boolean matches(Method method, Class<?> targetClass, @Nullable Object... args) {
344344
ShadowMatch shadowMatch = getTargetShadowMatch(method, targetClass);
345345

346346
// Bind Spring AOP proxy to AspectJ "this" and Spring AOP target to AspectJ target,

spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/InstantiationModelAwarePointcutAdvisorImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public boolean matches(Method method, Class<?> targetClass) {
289289
}
290290

291291
@Override
292-
public boolean matches(Method method, Class<?> targetClass, Object... args) {
292+
public boolean matches(Method method, Class<?> targetClass, @Nullable Object... args) {
293293
// This can match only on declared pointcut.
294294
return (isAspectMaterialized() && this.declaredPointcut.matches(method, targetClass, args));
295295
}

spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public boolean isRuntime() {
144144
}
145145

146146
@Override
147-
public boolean matches(Method method, Class<?> targetClass, Object... args) {
147+
public boolean matches(Method method, Class<?> targetClass, @Nullable Object... args) {
148148
incrementEvaluationCount();
149149

150150
for (StackTraceElement element : new Throwable().getStackTrace()) {

spring-aop/src/main/java/org/springframework/aop/support/MethodMatchers.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public boolean isRuntime() {
151151
}
152152

153153
@Override
154-
public boolean matches(Method method, Class<?> targetClass, Object... args) {
154+
public boolean matches(Method method, Class<?> targetClass, @Nullable Object... args) {
155155
return this.mm1.matches(method, targetClass, args) || this.mm2.matches(method, targetClass, args);
156156
}
157157

@@ -303,7 +303,7 @@ public boolean isRuntime() {
303303
}
304304

305305
@Override
306-
public boolean matches(Method method, Class<?> targetClass, Object... args) {
306+
public boolean matches(Method method, Class<?> targetClass, @Nullable Object... args) {
307307
// Because a dynamic intersection may be composed of a static and dynamic part,
308308
// we must avoid calling the 3-arg matches method on a dynamic matcher, as
309309
// it will probably be an unsupported operation.
@@ -373,7 +373,7 @@ public boolean isRuntime() {
373373
}
374374

375375
@Override
376-
public boolean matches(Method method, Class<?> targetClass, Object... args) {
376+
public boolean matches(Method method, Class<?> targetClass, @Nullable Object... args) {
377377
return !this.original.matches(method, targetClass, args);
378378
}
379379

spring-aop/src/main/java/org/springframework/aop/support/StaticMethodMatcher.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.lang.reflect.Method;
2020

21+
import org.jspecify.annotations.Nullable;
22+
2123
import org.springframework.aop.MethodMatcher;
2224

2325
/**
@@ -34,7 +36,7 @@ public final boolean isRuntime() {
3436
}
3537

3638
@Override
37-
public final boolean matches(Method method, Class<?> targetClass, Object... args) {
39+
public final boolean matches(Method method, Class<?> targetClass, @Nullable Object... args) {
3840
// should never be invoked because isRuntime() returns false
3941
throw new UnsupportedOperationException("Illegal MethodMatcher usage");
4042
}

spring-beans/src/main/java/org/springframework/beans/factory/ObjectProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ default T getObject() throws BeansException {
7777
* @throws BeansException in case of creation errors
7878
* @see #getObject()
7979
*/
80-
default T getObject(Object... args) throws BeansException {
80+
default T getObject(@Nullable Object... args) throws BeansException {
8181
throw new UnsupportedOperationException("Retrieval with arguments not supported -" +
8282
"for custom ObjectProvider classes, implement getObject(Object...) for your purposes");
8383
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public BeanWrapper autowireConstructor(String beanName, RootBeanDefinition mbd,
140140

141141
Constructor<?> constructorToUse = null;
142142
ArgumentsHolder argsHolderToUse = null;
143-
Object[] argsToUse = null;
143+
@Nullable Object[] argsToUse = null;
144144

145145
if (explicitArgs != null) {
146146
argsToUse = explicitArgs;
@@ -227,7 +227,7 @@ public BeanWrapper autowireConstructor(String beanName, RootBeanDefinition mbd,
227227
Class<?>[] paramTypes = candidate.getParameterTypes();
228228
if (resolvedValues != null) {
229229
try {
230-
String[] paramNames = null;
230+
@Nullable String[] paramNames = null;
231231
if (resolvedValues.containsNamedArgument()) {
232232
paramNames = ConstructorPropertiesChecker.evaluate(candidate, parameterCount);
233233
if (paramNames == null) {
@@ -437,7 +437,7 @@ public BeanWrapper instantiateUsingFactoryMethod(
437437
argsToUse = explicitArgs;
438438
}
439439
else {
440-
Object[] argsToResolve = null;
440+
@Nullable Object[] argsToResolve = null;
441441
synchronized (mbd.constructorArgumentLock) {
442442
factoryMethodToUse = (Method) mbd.resolvedConstructorOrFactoryMethod;
443443
if (factoryMethodToUse != null && mbd.constructorArgumentsResolved) {
@@ -536,7 +536,7 @@ public BeanWrapper instantiateUsingFactoryMethod(
536536
else {
537537
// Resolved constructor arguments: type conversion and/or autowiring necessary.
538538
try {
539-
String[] paramNames = null;
539+
@Nullable String[] paramNames = null;
540540
if (resolvedValues != null && resolvedValues.containsNamedArgument()) {
541541
ParameterNameDiscoverer pnd = this.beanFactory.getParameterNameDiscoverer();
542542
if (pnd != null) {
@@ -719,7 +719,7 @@ private int resolveConstructorArguments(String beanName, RootBeanDefinition mbd,
719719
*/
720720
private ArgumentsHolder createArgumentArray(
721721
String beanName, RootBeanDefinition mbd, @Nullable ConstructorArgumentValues resolvedValues,
722-
BeanWrapper bw, Class<?>[] paramTypes, String @Nullable [] paramNames, Executable executable,
722+
BeanWrapper bw, Class<?>[] paramTypes, @Nullable String @Nullable [] paramNames, Executable executable,
723723
boolean autowiring, boolean fallback) throws UnsatisfiedDependencyException {
724724

725725
TypeConverter customConverter = this.beanFactory.getCustomTypeConverter();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ public T getObject() throws BeansException {
422422
return resolved;
423423
}
424424
@Override
425-
public T getObject(Object... args) throws BeansException {
425+
public T getObject(@Nullable Object... args) throws BeansException {
426426
T resolved = resolveBean(requiredType, args, false);
427427
if (resolved == null) {
428428
throw new NoSuchBeanDefinitionException(requiredType);
@@ -2147,7 +2147,7 @@ private void checkBeanNotOfRequiredType(Class<?> type, DependencyDescriptor desc
21472147
* Create an {@link Optional} wrapper for the specified dependency.
21482148
*/
21492149
private Optional<?> createOptionalDependency(
2150-
DependencyDescriptor descriptor, @Nullable String beanName, final Object... args) {
2150+
DependencyDescriptor descriptor, @Nullable String beanName, final @Nullable Object... args) {
21512151

21522152
DependencyDescriptor descriptorToUse = new NestedDependencyDescriptor(descriptor) {
21532153
@Override
@@ -2317,7 +2317,7 @@ public Object getObject() throws BeansException {
23172317
}
23182318

23192319
@Override
2320-
public Object getObject(final Object... args) throws BeansException {
2320+
public Object getObject(final @Nullable Object... args) throws BeansException {
23212321
if (this.optional) {
23222322
return createOptionalDependency(this.descriptor, this.beanName, args);
23232323
}

0 commit comments

Comments
 (0)