TargetSource.getTarget() is nullable again (for compatibility with MethodInvocation.getThis)

Issue: SPR-15651
This commit is contained in:
Juergen Hoeller
2017-06-12 22:54:18 +02:00
parent 233c15b80e
commit 47ec966757
8 changed files with 67 additions and 47 deletions

View File

@@ -29,6 +29,7 @@ import org.springframework.util.Assert;
* {@link org.springframework.aop.framework.AopProxyUtils AopProxyUtils}.
*
* @author Sam Brannen
* @author Juergen Hoeller
* @since 4.2
* @see org.springframework.aop.support.AopUtils
* @see org.springframework.aop.framework.AopProxyUtils
@@ -54,7 +55,10 @@ public abstract class AopTestUtils {
Assert.notNull(candidate, "Candidate must not be null");
try {
if (AopUtils.isAopProxy(candidate) && candidate instanceof Advised) {
return (T) ((Advised) candidate).getTargetSource().getTarget();
Object target = ((Advised) candidate).getTargetSource().getTarget();
if (target != null) {
return (T) target;
}
}
}
catch (Throwable ex) {
@@ -83,7 +87,10 @@ public abstract class AopTestUtils {
Assert.notNull(candidate, "Candidate must not be null");
try {
if (AopUtils.isAopProxy(candidate) && candidate instanceof Advised) {
return (T) getUltimateTargetObject(((Advised) candidate).getTargetSource().getTarget());
Object target = ((Advised) candidate).getTargetSource().getTarget();
if (target != null) {
return (T) getUltimateTargetObject(target);
}
}
}
catch (Throwable ex) {