Browse Source

Refine spring-aop arguments nullness

See gh-28797
pull/34207/head
Sébastien Deleuze 12 months ago
parent
commit
292a3a4895
  1. 4
      spring-aop/src/main/java/org/springframework/aop/ProxyMethodInvocation.java
  2. 2
      spring-aop/src/main/java/org/springframework/aop/framework/AopProxyUtils.java
  3. 12
      spring-aop/src/main/java/org/springframework/aop/framework/ReflectiveMethodInvocation.java
  4. 4
      spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java

4
spring-aop/src/main/java/org/springframework/aop/ProxyMethodInvocation.java

@ -58,14 +58,14 @@ public interface ProxyMethodInvocation extends MethodInvocation {
* @return an invocable clone of this invocation. * @return an invocable clone of this invocation.
* {@code proceed()} can be called once per clone. * {@code proceed()} can be called once per clone.
*/ */
MethodInvocation invocableClone(Object... arguments); MethodInvocation invocableClone(@Nullable Object... arguments);
/** /**
* Set the arguments to be used on subsequent invocations in the any advice * Set the arguments to be used on subsequent invocations in the any advice
* in this chain. * in this chain.
* @param arguments the argument array * @param arguments the argument array
*/ */
void setArguments(Object... arguments); void setArguments(@Nullable Object... arguments);
/** /**
* Add the specified user attribute with the given value to this invocation. * Add the specified user attribute with the given value to this invocation.

2
spring-aop/src/main/java/org/springframework/aop/framework/AopProxyUtils.java

@ -253,7 +253,7 @@ public abstract class AopProxyUtils {
* @return a cloned argument array, or the original if no adaptation is needed * @return a cloned argument array, or the original if no adaptation is needed
* @since 4.2.3 * @since 4.2.3
*/ */
static Object[] adaptArgumentsIfNecessary(Method method, Object @Nullable [] arguments) { static @Nullable Object[] adaptArgumentsIfNecessary(Method method, @Nullable Object[] arguments) {
if (ObjectUtils.isEmpty(arguments)) { if (ObjectUtils.isEmpty(arguments)) {
return new Object[0]; return new Object[0];
} }

12
spring-aop/src/main/java/org/springframework/aop/framework/ReflectiveMethodInvocation.java

@ -67,7 +67,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
protected final Method method; protected final Method method;
protected Object[] arguments; protected @Nullable Object[] arguments;
private final @Nullable Class<?> targetClass; private final @Nullable Class<?> targetClass;
@ -103,7 +103,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
* but would complicate the code. And it would work only for static pointcuts. * but would complicate the code. And it would work only for static pointcuts.
*/ */
protected ReflectiveMethodInvocation( protected ReflectiveMethodInvocation(
Object proxy, @Nullable Object target, Method method, Object @Nullable [] arguments, Object proxy, @Nullable Object target, Method method, @Nullable Object[] arguments,
@Nullable Class<?> targetClass, List<Object> interceptorsAndDynamicMethodMatchers) { @Nullable Class<?> targetClass, List<Object> interceptorsAndDynamicMethodMatchers) {
this.proxy = proxy; this.proxy = proxy;
@ -141,12 +141,13 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
} }
@Override @Override
public final Object[] getArguments() { public final @Nullable Object[] getArguments() {
return this.arguments; return this.arguments;
} }
@Override @Override
public void setArguments(Object... arguments) { @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1113
public void setArguments(@Nullable Object... arguments) {
this.arguments = arguments; this.arguments = arguments;
} }
@ -218,7 +219,8 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea
* @see java.lang.Object#clone() * @see java.lang.Object#clone()
*/ */
@Override @Override
public MethodInvocation invocableClone(Object... arguments) { @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1113
public MethodInvocation invocableClone(@Nullable Object... arguments) {
// Force initialization of the user attributes Map, // Force initialization of the user attributes Map,
// for having a shared Map reference in the clone. // for having a shared Map reference in the clone.
if (this.userAttributes == null) { if (this.userAttributes == null) {

4
spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java

@ -347,7 +347,7 @@ public abstract class AopUtils {
* @throws Throwable if thrown by the target method * @throws Throwable if thrown by the target method
* @throws org.springframework.aop.AopInvocationException in case of a reflection error * @throws org.springframework.aop.AopInvocationException in case of a reflection error
*/ */
public static @Nullable Object invokeJoinpointUsingReflection(@Nullable Object target, Method method, Object[] args) public static @Nullable Object invokeJoinpointUsingReflection(@Nullable Object target, Method method, @Nullable Object[] args)
throws Throwable { throws Throwable {
// Use reflection to invoke the method. // Use reflection to invoke the method.
@ -377,7 +377,7 @@ public abstract class AopUtils {
*/ */
private static class KotlinDelegate { private static class KotlinDelegate {
public static Object invokeSuspendingFunction(Method method, @Nullable Object target, Object... args) { public static Object invokeSuspendingFunction(Method method, @Nullable Object target, @Nullable Object... args) {
Continuation<?> continuation = (Continuation<?>) args[args.length -1]; Continuation<?> continuation = (Continuation<?>) args[args.length -1];
Assert.state(continuation != null, "No Continuation available"); Assert.state(continuation != null, "No Continuation available");
CoroutineContext context = continuation.getContext().minusKey(Job.Key); CoroutineContext context = continuation.getContext().minusKey(Job.Key);

Loading…
Cancel
Save