@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2024 the original author or authors .
* Copyright 2002 - 2025 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 .
@ -112,12 +112,12 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@@ -112,12 +112,12 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
private BeanFactory beanFactory ;
@Nullable
private transient ClassLoader pointcutClassLoader ;
private transient volatile ClassLoader pointcutClassLoader ;
@Nullable
private transient PointcutExpression pointcutExpression ;
private transient volatile PointcutExpression pointcutExpression ;
private transient boolean pointcutParsingFailed = false ;
private transient volatile boolean pointcutParsingFailed ;
/ * *
@ -197,11 +197,14 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@@ -197,11 +197,14 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
* Lazily build the underlying AspectJ pointcut expression .
* /
private PointcutExpression obtainPointcutExpression ( ) {
if ( this . pointcutExpression = = null ) {
this . pointcutClassLoader = determinePointcutClassLoader ( ) ;
this . pointcutExpression = buildPointcutExpression ( this . pointcutClassLoader ) ;
PointcutExpression pointcutExpression = this . pointcutExpression ;
if ( pointcutExpression = = null ) {
ClassLoader pointcutClassLoader = determinePointcutClassLoader ( ) ;
pointcutExpression = buildPointcutExpression ( pointcutClassLoader ) ;
this . pointcutClassLoader = pointcutClassLoader ;
this . pointcutExpression = pointcutExpression ;
}
return this . pointcutExpression ;
return pointcutExpression ;
}
/ * *
@ -467,40 +470,24 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@@ -467,40 +470,24 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
}
private ShadowMatch getShadowMatch ( Method targetMethod , Method originalMethod ) {
ShadowMatch shadowMatch = ShadowMatchUtils . getShadowMatch ( this , targetMethod ) ;
ShadowMatchKey key = new ShadowMatchKey ( this , targetMethod ) ;
ShadowMatch shadowMatch = ShadowMatchUtils . getShadowMatch ( key ) ;
if ( shadowMatch = = null ) {
PointcutExpression fallbackExpression = null ;
Method methodToMatch = targetMethod ;
try {
try {
shadowMatch = obtainPointcutExpression ( ) . matchesMethodExecution ( methodToMatch ) ;
}
catch ( ReflectionWorldException ex ) {
// Failed to introspect target method, probably because it has been loaded
// in a special ClassLoader. Let's try the declaring ClassLoader instead...
try {
fallbackExpression = getFallbackPointcutExpression ( methodToMatch . getDeclaringClass ( ) ) ;
if ( fallbackExpression ! = null ) {
shadowMatch = fallbackExpression . matchesMethodExecution ( methodToMatch ) ;
}
}
catch ( ReflectionWorldException ex2 ) {
fallbackExpression = null ;
}
PointcutExpression pointcutExpression = obtainPointcutExpression ( ) ;
synchronized ( pointcutExpression ) {
shadowMatch = ShadowMatchUtils . getShadowMatch ( key ) ;
if ( shadowMatch ! = null ) {
return shadowMatch ;
}
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), as well as for annotation pointcuts.
methodToMatch = originalMethod ;
PointcutExpression fallbackExpression = null ;
Method methodToMatch = targetMethod ;
try {
try {
shadowMatch = obtainPointcutExpression ( ) . matchesMethodExecution ( methodToMatch ) ;
shadowMatch = pointcutExpression . matchesMethodExecution ( methodToMatch ) ;
}
catch ( ReflectionWorldException ex ) {
// Could neither introspect the target class nor the proxy class ->
// let's try the original method's declaring class before we give up ...
// Failed to introspect target method, probably because it has been loaded
// in a special ClassLoader. Let's try the declaring ClassLoader instead...
try {
fallbackExpression = getFallbackPointcutExpression ( methodToMatch . getDeclaringClass ( ) ) ;
if ( fallbackExpression ! = null ) {
@ -511,21 +498,45 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@@ -511,21 +498,45 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
fallbackExpression = null ;
}
}
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), as well as for annotation pointcuts.
methodToMatch = originalMethod ;
try {
shadowMatch = pointcutExpression . matchesMethodExecution ( methodToMatch ) ;
}
catch ( ReflectionWorldException ex ) {
// Could neither introspect the target class nor the proxy class ->
// let's try the original method's declaring class before we give up...
try {
fallbackExpression = getFallbackPointcutExpression ( methodToMatch . getDeclaringClass ( ) ) ;
if ( fallbackExpression ! = null ) {
shadowMatch = fallbackExpression . matchesMethodExecution ( methodToMatch ) ;
}
}
catch ( ReflectionWorldException ex2 ) {
fallbackExpression = null ;
}
}
}
}
catch ( Throwable ex ) {
// Possibly AspectJ 1.8.10 encountering an invalid signature
logger . debug ( "PointcutExpression matching rejected target method" , ex ) ;
fallbackExpression = null ;
}
if ( shadowMatch = = null ) {
shadowMatch = new ShadowMatchImpl ( org . aspectj . util . FuzzyBoolean . NO , null , null , null ) ;
}
else if ( shadowMatch . maybeMatches ( ) & & fallbackExpression ! = null ) {
shadowMatch = new DefensiveShadowMatch ( shadowMatch ,
fallbackExpression . matchesMethodExecution ( methodToMatch ) ) ;
}
shadowMatch = ShadowMatchUtils . setShadowMatch ( key , shadowMatch ) ;
}
catch ( Throwable ex ) {
// Possibly AspectJ 1.8.10 encountering an invalid signature
logger . debug ( "PointcutExpression matching rejected target method" , ex ) ;
fallbackExpression = null ;
}
if ( shadowMatch = = null ) {
shadowMatch = new ShadowMatchImpl ( org . aspectj . util . FuzzyBoolean . NO , null , null , null ) ;
}
else if ( shadowMatch . maybeMatches ( ) & & fallbackExpression ! = null ) {
shadowMatch = new DefensiveShadowMatch ( shadowMatch ,
fallbackExpression . matchesMethodExecution ( methodToMatch ) ) ;
}
shadowMatch = ShadowMatchUtils . setShadowMatch ( this , targetMethod , shadowMatch ) ;
}
return shadowMatch ;
}
@ -720,4 +731,8 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
@@ -720,4 +731,8 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
}
}
private record ShadowMatchKey ( AspectJExpressionPointcut expression , Method method ) {
}
}