From 0d8dee2878be188cf144da6f4cd26b225863f865 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 23 Nov 2023 16:14:33 +0100 Subject: [PATCH] Apply fallback for proxy with negative match or annotation pointcut See gh-30534 --- .../aop/aspectj/AspectJExpressionPointcut.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java index 76a50d105bd1..d9a72b6417f1 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java @@ -471,10 +471,12 @@ private ShadowMatch getShadowMatch(Method targetMethod, Method originalMethod) { fallbackExpression = null; } } - if (targetMethod != originalMethod && (shadowMatch == null || shouldFallback(targetMethod))) { + if (targetMethod != originalMethod && (shadowMatch == null || + (Proxy.isProxyClass(targetMethod.getDeclaringClass()) && + (shadowMatch.neverMatches() || containsAnnotationPointcut())))) { // Fall back to the plain original method in case of no resolvable match or a // negative match on a proxy class (which doesn't carry any annotations on its - // redeclared methods). + // redeclared methods), as well as for annotation pointcuts. methodToMatch = originalMethod; try { shadowMatch = obtainPointcutExpression().matchesMethodExecution(methodToMatch); @@ -513,13 +515,11 @@ else if (shadowMatch.maybeMatches() && fallbackExpression != null) { return shadowMatch; } - private boolean shouldFallback(Method targetMethod) { - if (!Proxy.isProxyClass(targetMethod.getDeclaringClass())) { - return false; - } - return this.resolveExpression().contains("@annotation"); + private boolean containsAnnotationPointcut() { + return resolveExpression().contains("@annotation"); } + @Override public boolean equals(@Nullable Object other) { return (this == other || (other instanceof AspectJExpressionPointcut that &&