Explicit nullability declarations for all AOP Alliance methods
Includes consistent declarations in AOP Alliance related Spring AOP code. Closes gh-24117
This commit is contained in:
parent
60fac67884
commit
3c1ee64b7f
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.aopalliance.intercept;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Intercepts the construction of a new object.
|
||||
*
|
||||
|
@ -54,6 +56,7 @@ public interface ConstructorInterceptor extends Interceptor {
|
|||
* @throws Throwable if the interceptors or the target object
|
||||
* throws an exception
|
||||
*/
|
||||
@Nonnull
|
||||
Object construct(ConstructorInvocation invocation) throws Throwable;
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ package org.aopalliance.intercept;
|
|||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Description of an invocation to a constructor, given to an
|
||||
* interceptor upon constructor-call.
|
||||
|
@ -36,6 +38,7 @@ public interface ConstructorInvocation extends Invocation {
|
|||
* {@link Joinpoint#getStaticPart()} method (same result).
|
||||
* @return the constructor being called
|
||||
*/
|
||||
@Nonnull
|
||||
Constructor<?> getConstructor();
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.aopalliance.intercept;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* This interface represents an invocation in the program.
|
||||
*
|
||||
|
@ -32,6 +34,7 @@ public interface Invocation extends Joinpoint {
|
|||
* array to change the arguments.
|
||||
* @return the argument of the invocation
|
||||
*/
|
||||
@Nonnull
|
||||
Object[] getArguments();
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,9 @@ package org.aopalliance.intercept;
|
|||
|
||||
import java.lang.reflect.AccessibleObject;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* This interface represents a generic runtime joinpoint (in the AOP
|
||||
* terminology).
|
||||
|
@ -46,6 +49,7 @@ public interface Joinpoint {
|
|||
* @return see the children interfaces' proceed definition
|
||||
* @throws Throwable if the joinpoint throws an exception
|
||||
*/
|
||||
@Nullable
|
||||
Object proceed() throws Throwable;
|
||||
|
||||
/**
|
||||
|
@ -53,6 +57,7 @@ public interface Joinpoint {
|
|||
* <p>For instance, the target object for an invocation.
|
||||
* @return the object (can be null if the accessible object is static)
|
||||
*/
|
||||
@Nullable
|
||||
Object getThis();
|
||||
|
||||
/**
|
||||
|
@ -60,6 +65,7 @@ public interface Joinpoint {
|
|||
* <p>The static part is an accessible object on which a chain of
|
||||
* interceptors are installed.
|
||||
*/
|
||||
@Nonnull
|
||||
AccessibleObject getStaticPart();
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
|
||||
package org.aopalliance.intercept;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Intercepts calls on an interface on its way to the target. These
|
||||
* are nested "on top" of the target.
|
||||
|
@ -52,6 +55,7 @@ public interface MethodInterceptor extends Interceptor {
|
|||
* @throws Throwable if the interceptors or the target object
|
||||
* throws an exception
|
||||
*/
|
||||
Object invoke(MethodInvocation invocation) throws Throwable;
|
||||
@Nullable
|
||||
Object invoke(@Nonnull MethodInvocation invocation) throws Throwable;
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ package org.aopalliance.intercept;
|
|||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Description of an invocation to a method, given to an interceptor
|
||||
* upon method-call.
|
||||
|
@ -36,6 +38,7 @@ public interface MethodInvocation extends Invocation {
|
|||
* {@link Joinpoint#getStaticPart()} method (same result).
|
||||
* @return the method being called
|
||||
*/
|
||||
@Nonnull
|
||||
Method getMethod();
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -23,6 +23,7 @@ import org.aopalliance.intercept.MethodInterceptor;
|
|||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.springframework.aop.AfterAdvice;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Spring AOP advice wrapping an AspectJ after advice method.
|
||||
|
@ -42,6 +43,7 @@ public class AspectJAfterAdvice extends AbstractAspectJAdvice
|
|||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
try {
|
||||
return mi.proceed();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -23,6 +23,7 @@ import org.aopalliance.intercept.MethodInterceptor;
|
|||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.springframework.aop.AfterAdvice;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Spring AOP advice wrapping an AspectJ after-throwing advice method.
|
||||
|
@ -57,6 +58,7 @@ public class AspectJAfterThrowingAdvice extends AbstractAspectJAdvice
|
|||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
try {
|
||||
return mi.proceed();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -25,6 +25,7 @@ import org.aspectj.lang.ProceedingJoinPoint;
|
|||
import org.aspectj.weaver.tools.JoinPointMatch;
|
||||
|
||||
import org.springframework.aop.ProxyMethodInvocation;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Spring AOP around advice (MethodInterceptor) that wraps
|
||||
|
@ -60,6 +61,7 @@ public class AspectJAroundAdvice extends AbstractAspectJAdvice implements Method
|
|||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
if (!(mi instanceof ProxyMethodInvocation)) {
|
||||
throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -84,11 +84,13 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint,
|
|||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object proceed() throws Throwable {
|
||||
return this.methodInvocation.invocableClone().proceed();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object proceed(Object[] arguments) throws Throwable {
|
||||
Assert.notNull(arguments, "Argument array passed to proceed cannot be null");
|
||||
if (arguments.length != this.methodInvocation.getArguments().length) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -23,6 +23,7 @@ import org.aopalliance.intercept.MethodInvocation;
|
|||
|
||||
import org.springframework.aop.AfterAdvice;
|
||||
import org.springframework.aop.AfterReturningAdvice;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
|
@ -51,6 +52,7 @@ public class AfterReturningAdviceInterceptor implements MethodInterceptor, After
|
|||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
Object retVal = mi.proceed();
|
||||
this.advice.afterReturning(retVal, mi.getMethod(), mi.getArguments(), mi.getThis());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -23,6 +23,7 @@ import org.aopalliance.intercept.MethodInvocation;
|
|||
|
||||
import org.springframework.aop.BeforeAdvice;
|
||||
import org.springframework.aop.MethodBeforeAdvice;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
|
@ -51,6 +52,7 @@ public class MethodBeforeAdviceInterceptor implements MethodInterceptor, BeforeA
|
|||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
this.advice.before(mi.getMethod(), mi.getArguments(), mi.getThis());
|
||||
return mi.proceed();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -107,6 +107,7 @@ public class ThrowsAdviceInterceptor implements MethodInterceptor, AfterAdvice {
|
|||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
try {
|
||||
return mi.proceed();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -25,6 +25,7 @@ import org.apache.commons.logging.LogFactory;
|
|||
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Base {@code MethodInterceptor} implementation for tracing.
|
||||
|
@ -151,6 +152,7 @@ public abstract class AbstractTraceInterceptor implements MethodInterceptor, Ser
|
|||
}
|
||||
else {
|
||||
Object target = invocation.getThis();
|
||||
Assert.state(target != null, "Target must not be null");
|
||||
return LogFactory.getLog(getClassForLogging(target));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -21,6 +21,7 @@ import java.io.Serializable;
|
|||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ConcurrencyThrottleSupport;
|
||||
|
||||
/**
|
||||
|
@ -48,6 +49,7 @@ public class ConcurrencyThrottleInterceptor extends ConcurrencyThrottleSupport
|
|||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
|
||||
beforeAccess();
|
||||
try {
|
||||
|
|
|
@ -296,6 +296,8 @@ public class CustomizableTraceInterceptor extends AbstractTraceInterceptor {
|
|||
@Nullable Object returnValue, @Nullable Throwable throwable, long invocationTime) {
|
||||
|
||||
Matcher matcher = PATTERN.matcher(message);
|
||||
Object target = methodInvocation.getThis();
|
||||
Assert.state(target != null, "Target must not be null");
|
||||
|
||||
StringBuffer output = new StringBuffer();
|
||||
while (matcher.find()) {
|
||||
|
@ -304,11 +306,11 @@ public class CustomizableTraceInterceptor extends AbstractTraceInterceptor {
|
|||
matcher.appendReplacement(output, Matcher.quoteReplacement(methodInvocation.getMethod().getName()));
|
||||
}
|
||||
else if (PLACEHOLDER_TARGET_CLASS_NAME.equals(match)) {
|
||||
String className = getClassForLogging(methodInvocation.getThis()).getName();
|
||||
String className = getClassForLogging(target).getName();
|
||||
matcher.appendReplacement(output, Matcher.quoteReplacement(className));
|
||||
}
|
||||
else if (PLACEHOLDER_TARGET_CLASS_SHORT_NAME.equals(match)) {
|
||||
String shortName = ClassUtils.getShortName(getClassForLogging(methodInvocation.getThis()));
|
||||
String shortName = ClassUtils.getShortName(getClassForLogging(target));
|
||||
matcher.appendReplacement(output, Matcher.quoteReplacement(shortName));
|
||||
}
|
||||
else if (PLACEHOLDER_ARGUMENTS.equals(match)) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -18,6 +18,8 @@ package org.springframework.aop.interceptor;
|
|||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* AOP Alliance {@code MethodInterceptor} that can be introduced in a chain
|
||||
* to display verbose information about intercepted invocations to the logger.
|
||||
|
@ -56,6 +58,7 @@ public class DebugInterceptor extends SimpleTraceInterceptor {
|
|||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
synchronized (this) {
|
||||
this.count++;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -25,6 +25,7 @@ import org.springframework.aop.support.DefaultIntroductionAdvisor;
|
|||
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||
import org.springframework.aop.support.DelegatingIntroductionInterceptor;
|
||||
import org.springframework.beans.factory.NamedBean;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Convenient methods for creating advisors that may be used when autoproxying beans
|
||||
|
@ -110,6 +111,7 @@ public abstract class ExposeBeanNameAdvisors {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
if (!(mi instanceof ProxyMethodInvocation)) {
|
||||
throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
|
||||
|
@ -134,6 +136,7 @@ public abstract class ExposeBeanNameAdvisors {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
if (!(mi instanceof ProxyMethodInvocation)) {
|
||||
throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.springframework.aop.Advisor;
|
|||
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||
import org.springframework.core.NamedThreadLocal;
|
||||
import org.springframework.core.PriorityOrdered;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Interceptor that exposes the current {@link org.aopalliance.intercept.MethodInvocation}
|
||||
|
@ -88,6 +89,7 @@ public final class ExposeInvocationInterceptor implements MethodInterceptor, Pri
|
|||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
MethodInvocation oldInvocation = invocation.get();
|
||||
invocation.set(mi);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -19,6 +19,8 @@ package org.springframework.aop.interceptor;
|
|||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Simple AOP Alliance {@code MethodInterceptor} that can be introduced
|
||||
* in a chain to display verbose trace information about intercepted method
|
||||
|
@ -73,7 +75,9 @@ public class SimpleTraceInterceptor extends AbstractTraceInterceptor {
|
|||
* @return the description
|
||||
*/
|
||||
protected String getInvocationDescription(MethodInvocation invocation) {
|
||||
String className = invocation.getThis().getClass().getName();
|
||||
Object target = invocation.getThis();
|
||||
Assert.state(target != null, "Target must not be null");
|
||||
String className = target.getClass().getName();
|
||||
return "method '" + invocation.getMethod().getName() + "' of class [" + className + "]";
|
||||
}
|
||||
|
||||
|
|
|
@ -114,12 +114,13 @@ public class DelegatePerTargetObjectIntroductionInterceptor extends Introduction
|
|||
* that it is introduced into. This method is <strong>never</strong> called for
|
||||
* {@link MethodInvocation MethodInvocations} on the introduced interfaces.
|
||||
*/
|
||||
@Nullable
|
||||
protected Object doProceed(MethodInvocation mi) throws Throwable {
|
||||
// If we get here, just pass the invocation on.
|
||||
return mi.proceed();
|
||||
}
|
||||
|
||||
private Object getIntroductionDelegateFor(Object targetObject) {
|
||||
private Object getIntroductionDelegateFor(@Nullable Object targetObject) {
|
||||
synchronized (this.delegateMap) {
|
||||
if (this.delegateMap.containsKey(targetObject)) {
|
||||
return this.delegateMap.get(targetObject);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -131,6 +131,7 @@ public class DelegatingIntroductionInterceptor extends IntroductionInfoSupport
|
|||
* that it is introduced into. This method is <strong>never</strong> called for
|
||||
* {@link MethodInvocation MethodInvocations} on the introduced interfaces.
|
||||
*/
|
||||
@Nullable
|
||||
protected Object doProceed(MethodInvocation mi) throws Throwable {
|
||||
// If we get here, just pass the invocation on.
|
||||
return mi.proceed();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -16,13 +16,11 @@
|
|||
|
||||
package org.springframework.aop.interceptor;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.beans.testfixture.beans.ITestBean;
|
||||
import org.springframework.beans.testfixture.beans.TestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.core.testfixture.io.ResourceTestUtils.qualifiedResource;
|
||||
|
@ -48,33 +46,3 @@ public class ExposeInvocationInterceptorTests {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
abstract class ExposedInvocationTestBean extends TestBean {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation();
|
||||
assertions(invocation);
|
||||
return super.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void absquatulate() {
|
||||
MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation();
|
||||
assertions(invocation);
|
||||
super.absquatulate();
|
||||
}
|
||||
|
||||
protected abstract void assertions(MethodInvocation invocation);
|
||||
}
|
||||
|
||||
|
||||
class InvocationCheckExposedInvocationTestBean extends ExposedInvocationTestBean {
|
||||
|
||||
@Override
|
||||
protected void assertions(MethodInvocation invocation) {
|
||||
assertThat(invocation.getThis() == this).isTrue();
|
||||
assertThat(ITestBean.class.isAssignableFrom(invocation.getMethod().getDeclaringClass())).as("Invocation should be on ITestBean: " + invocation.getMethod()).isTrue();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright 2002-2020 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.aop.interceptor;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.springframework.beans.testfixture.beans.TestBean;
|
||||
|
||||
abstract class ExposedInvocationTestBean extends TestBean {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation();
|
||||
assertions(invocation);
|
||||
return super.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void absquatulate() {
|
||||
MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation();
|
||||
assertions(invocation);
|
||||
super.absquatulate();
|
||||
}
|
||||
|
||||
protected abstract void assertions(MethodInvocation invocation);
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright 2002-2020 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.aop.interceptor;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.springframework.beans.testfixture.beans.ITestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class InvocationCheckExposedInvocationTestBean extends ExposedInvocationTestBean {
|
||||
|
||||
@Override
|
||||
protected void assertions(MethodInvocation invocation) {
|
||||
assertThat(invocation.getThis() == this).isTrue();
|
||||
assertThat(ITestBean.class.isAssignableFrom(invocation.getMethod().getDeclaringClass())).as("Invocation should be on ITestBean: " + invocation.getMethod()).isTrue();
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -165,6 +165,7 @@ public class JCacheAspectSupport extends AbstractCacheInvoker implements Initial
|
|||
* @return the result of the invocation
|
||||
* @see CacheOperationInvoker#invoke()
|
||||
*/
|
||||
@Nullable
|
||||
protected Object invokeOperation(CacheOperationInvoker invoker) {
|
||||
return invoker.invoke();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -27,6 +27,7 @@ import org.springframework.cache.interceptor.CacheErrorHandler;
|
|||
import org.springframework.cache.interceptor.CacheOperationInvoker;
|
||||
import org.springframework.cache.interceptor.SimpleCacheErrorHandler;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.function.SingletonSupplier;
|
||||
|
||||
/**
|
||||
|
@ -78,8 +79,10 @@ public class JCacheInterceptor extends JCacheAspectSupport implements MethodInte
|
|||
}
|
||||
};
|
||||
|
||||
Object target = invocation.getThis();
|
||||
Assert.state(target != null, "Target must not be null");
|
||||
try {
|
||||
return execute(aopAllianceInvoker, invocation.getThis(), method, invocation.getArguments());
|
||||
return execute(aopAllianceInvoker, target, method, invocation.getArguments());
|
||||
}
|
||||
catch (CacheOperationInvoker.ThrowableWrapper th) {
|
||||
throw th.getOriginal();
|
||||
|
|
|
@ -361,6 +361,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
|||
* @return the result of the invocation
|
||||
* @see CacheOperationInvoker#invoke()
|
||||
*/
|
||||
@Nullable
|
||||
protected Object invokeOperation(CacheOperationInvoker invoker) {
|
||||
return invoker.invoke();
|
||||
}
|
||||
|
@ -445,7 +446,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
|||
}
|
||||
|
||||
@Nullable
|
||||
private Object unwrapReturnValue(Object returnValue) {
|
||||
private Object unwrapReturnValue(@Nullable Object returnValue) {
|
||||
return ObjectUtils.unwrapOptional(returnValue);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -23,6 +23,7 @@ import org.aopalliance.intercept.MethodInterceptor;
|
|||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* AOP Alliance MethodInterceptor for declarative cache
|
||||
|
@ -57,8 +58,10 @@ public class CacheInterceptor extends CacheAspectSupport implements MethodInterc
|
|||
}
|
||||
};
|
||||
|
||||
Object target = invocation.getThis();
|
||||
Assert.state(target != null, "Target must not be null");
|
||||
try {
|
||||
return execute(aopAllianceInvoker, invocation.getThis(), method, invocation.getArguments());
|
||||
return execute(aopAllianceInvoker, target, method, invocation.getArguments());
|
||||
}
|
||||
catch (CacheOperationInvoker.ThrowableWrapper th) {
|
||||
throw th.getOriginal();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.springframework.cache.interceptor;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Abstract the invocation of a cache operation.
|
||||
*
|
||||
|
@ -36,6 +38,7 @@ public interface CacheOperationInvoker {
|
|||
* @return the result of the operation
|
||||
* @throws ThrowableWrapper if an error occurred while invoking the operation
|
||||
*/
|
||||
@Nullable
|
||||
Object invoke() throws ThrowableWrapper;
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -94,6 +94,7 @@ public class EventPublicationInterceptor
|
|||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
Object retVal = invocation.proceed();
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -368,6 +368,7 @@ public class JndiObjectFactoryBean extends JndiObjectLocator
|
|||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
Context ctx = (isEligible(invocation.getMethod()) ? this.jndiTemplate.getContext() : null);
|
||||
try {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -268,6 +268,7 @@ public class JndiRmiClientInterceptor extends JndiObjectLocator implements Metho
|
|||
* @see java.rmi.NoSuchObjectException
|
||||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
Object stub;
|
||||
try {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -255,6 +255,7 @@ public class RmiClientInterceptor extends RemoteInvocationBasedAccessor
|
|||
* @see java.rmi.NoSuchObjectException
|
||||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
Remote stub = getStub();
|
||||
try {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -18,6 +18,8 @@ package org.springframework.remoting.support;
|
|||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Abstract base class for remote service accessors that are based
|
||||
* on serialization of {@link RemoteInvocation} objects.
|
||||
|
@ -81,6 +83,7 @@ public abstract class RemoteInvocationBasedAccessor extends UrlBasedRemoteAccess
|
|||
* @throws Throwable if the invocation result is an exception
|
||||
* @see RemoteInvocationResult#recreate()
|
||||
*/
|
||||
@Nullable
|
||||
protected Object recreateRemoteInvocationResult(RemoteInvocationResult result) throws Throwable {
|
||||
return result.recreate();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -23,6 +23,7 @@ import org.aopalliance.intercept.MethodInvocation;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
|
@ -68,6 +69,7 @@ public class RemoteInvocationTraceInterceptor implements MethodInterceptor {
|
|||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
Method method = invocation.getMethod();
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
|
|
@ -33,6 +33,8 @@ import org.springframework.beans.factory.FactoryBean;
|
|||
import org.springframework.beans.factory.SmartFactoryBean;
|
||||
import org.springframework.core.BridgeMethodResolver;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
|
@ -87,7 +89,7 @@ public class MethodValidationInterceptor implements MethodInterceptor {
|
|||
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
// Avoid Validator invocation on FactoryBean.getObjectType/isSingleton
|
||||
if (isFactoryBeanMetadataMethod(invocation.getMethod())) {
|
||||
|
@ -101,17 +103,18 @@ public class MethodValidationInterceptor implements MethodInterceptor {
|
|||
Method methodToValidate = invocation.getMethod();
|
||||
Set<ConstraintViolation<Object>> result;
|
||||
|
||||
Object target = invocation.getThis();
|
||||
Assert.state(target != null, "Target must not be null");
|
||||
|
||||
try {
|
||||
result = execVal.validateParameters(
|
||||
invocation.getThis(), methodToValidate, invocation.getArguments(), groups);
|
||||
result = execVal.validateParameters(target, methodToValidate, invocation.getArguments(), groups);
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// Probably a generic type mismatch between interface and impl as reported in SPR-12237 / HV-1011
|
||||
// Let's try to find the bridged method on the implementation class...
|
||||
methodToValidate = BridgeMethodResolver.findBridgedMethod(
|
||||
ClassUtils.getMostSpecificMethod(invocation.getMethod(), invocation.getThis().getClass()));
|
||||
result = execVal.validateParameters(
|
||||
invocation.getThis(), methodToValidate, invocation.getArguments(), groups);
|
||||
ClassUtils.getMostSpecificMethod(invocation.getMethod(), target.getClass()));
|
||||
result = execVal.validateParameters(target, methodToValidate, invocation.getArguments(), groups);
|
||||
}
|
||||
if (!result.isEmpty()) {
|
||||
throw new ConstraintViolationException(result);
|
||||
|
@ -119,7 +122,7 @@ public class MethodValidationInterceptor implements MethodInterceptor {
|
|||
|
||||
Object returnValue = invocation.proceed();
|
||||
|
||||
result = execVal.validateReturnValue(invocation.getThis(), methodToValidate, returnValue, groups);
|
||||
result = execVal.validateReturnValue(target, methodToValidate, returnValue, groups);
|
||||
if (!result.isEmpty()) {
|
||||
throw new ConstraintViolationException(result);
|
||||
}
|
||||
|
@ -158,7 +161,9 @@ public class MethodValidationInterceptor implements MethodInterceptor {
|
|||
protected Class<?>[] determineValidationGroups(MethodInvocation invocation) {
|
||||
Validated validatedAnn = AnnotationUtils.findAnnotation(invocation.getMethod(), Validated.class);
|
||||
if (validatedAnn == null) {
|
||||
validatedAnn = AnnotationUtils.findAnnotation(invocation.getThis().getClass(), Validated.class);
|
||||
Object target = invocation.getThis();
|
||||
Assert.state(target != null, "Target must not be null");
|
||||
validatedAnn = AnnotationUtils.findAnnotation(target.getClass(), Validated.class);
|
||||
}
|
||||
return (validatedAnn != null ? validatedAnn.value() : new Class<?>[0]);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -78,6 +78,7 @@ public class OpenSessionInterceptor implements MethodInterceptor, InitializingBe
|
|||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable {
|
||||
SessionFactory sf = getSessionFactory();
|
||||
Assert.state(sf != null, "No SessionFactory set");
|
||||
|
|
|
@ -134,6 +134,7 @@ public class PersistenceExceptionTranslationInterceptor
|
|||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
try {
|
||||
return mi.proceed();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -107,6 +107,7 @@ public class GenericMessageEndpointFactory extends AbstractMessageEndpointFactor
|
|||
private class GenericMessageEndpoint extends AbstractMessageEndpoint implements MethodInterceptor {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
|
||||
Throwable endpointEx = null;
|
||||
boolean applyDeliveryCalls = !hasBeforeDeliveryBeenCalled();
|
||||
|
|
|
@ -375,7 +375,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
|
|||
cleanupTransactionInfo(txInfo);
|
||||
}
|
||||
|
||||
if (vavrPresent && VavrDelegate.isVavrTry(retVal)) {
|
||||
if (retVal != null && vavrPresent && VavrDelegate.isVavrTry(retVal)) {
|
||||
// Set rollback-only in case of Vavr failure matching our rollback rules...
|
||||
TransactionStatus status = txInfo.getTransactionStatus();
|
||||
if (status != null && txAttr != null) {
|
||||
|
@ -396,7 +396,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
|
|||
TransactionInfo txInfo = prepareTransactionInfo(ptm, txAttr, joinpointIdentification, status);
|
||||
try {
|
||||
Object retVal = invocation.proceedWithInvocation();
|
||||
if (vavrPresent && VavrDelegate.isVavrTry(retVal)) {
|
||||
if (retVal != null && vavrPresent && VavrDelegate.isVavrTry(retVal)) {
|
||||
// Set rollback-only in case of Vavr failure matching our rollback rules...
|
||||
retVal = VavrDelegate.evaluateTryFailure(retVal, txAttr, status);
|
||||
}
|
||||
|
@ -780,6 +780,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
|
|||
@FunctionalInterface
|
||||
protected interface InvocationCallback {
|
||||
|
||||
@Nullable
|
||||
Object proceedWithInvocation() throws Throwable;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
|
@ -142,6 +142,7 @@ public class HttpInvokerClientInterceptor extends RemoteInvocationBasedAccessor
|
|||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
|
||||
if (AopUtils.isToStringMethod(methodInvocation.getMethod())) {
|
||||
return "HTTP invoker proxy for service URL [" + getServiceUrl() + "]";
|
||||
|
|
Loading…
Reference in New Issue