Skip to content

Commit ee77524

Browse files
committed
Defensively catch IllegalStateException from match attempts (for compatibility with AspectJ 1.8.10)
Issue: SPR-15019 (cherry picked from commit f0c3d50)
1 parent bcdda91 commit ee77524

File tree

1 file changed

+32
-21
lines changed

1 file changed

+32
-21
lines changed

spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ public boolean matches(Class<?> targetClass) {
261261
catch (BCException ex) {
262262
logger.debug("PointcutExpression matching rejected target class", ex);
263263
}
264+
catch (IllegalStateException ex) {
265+
// AspectJ 1.8.10: encountered invalid signature
266+
logger.debug("PointcutExpression matching rejected target class", ex);
267+
}
264268
return false;
265269
}
266270

@@ -413,39 +417,46 @@ private ShadowMatch getShadowMatch(Method targetMethod, Method originalMethod) {
413417
shadowMatch = this.shadowMatchCache.get(targetMethod);
414418
if (shadowMatch == null) {
415419
try {
416-
shadowMatch = this.pointcutExpression.matchesMethodExecution(methodToMatch);
417-
}
418-
catch (ReflectionWorldException ex) {
419-
// Failed to introspect target method, probably because it has been loaded
420-
// in a special ClassLoader. Let's try the declaring ClassLoader instead...
421-
try {
422-
fallbackExpression = getFallbackPointcutExpression(methodToMatch.getDeclaringClass());
423-
if (fallbackExpression != null) {
424-
shadowMatch = fallbackExpression.matchesMethodExecution(methodToMatch);
425-
}
426-
}
427-
catch (ReflectionWorldException ex2) {
428-
fallbackExpression = null;
429-
}
430-
}
431-
if (shadowMatch == null && targetMethod != originalMethod) {
432-
methodToMatch = originalMethod;
433420
try {
434421
shadowMatch = this.pointcutExpression.matchesMethodExecution(methodToMatch);
435422
}
436-
catch (ReflectionWorldException ex3) {
437-
// Could neither introspect the target class nor the proxy class ->
438-
// let's try the original method's declaring class before we give up...
423+
catch (ReflectionWorldException ex) {
424+
// Failed to introspect target method, probably because it has been loaded
425+
// in a special ClassLoader. Let's try the declaring ClassLoader instead...
439426
try {
440427
fallbackExpression = getFallbackPointcutExpression(methodToMatch.getDeclaringClass());
441428
if (fallbackExpression != null) {
442429
shadowMatch = fallbackExpression.matchesMethodExecution(methodToMatch);
443430
}
444431
}
445-
catch (ReflectionWorldException ex4) {
432+
catch (ReflectionWorldException ex2) {
446433
fallbackExpression = null;
447434
}
448435
}
436+
if (shadowMatch == null && targetMethod != originalMethod) {
437+
methodToMatch = originalMethod;
438+
try {
439+
shadowMatch = this.pointcutExpression.matchesMethodExecution(methodToMatch);
440+
}
441+
catch (ReflectionWorldException ex3) {
442+
// Could neither introspect the target class nor the proxy class ->
443+
// let's try the original method's declaring class before we give up...
444+
try {
445+
fallbackExpression = getFallbackPointcutExpression(methodToMatch.getDeclaringClass());
446+
if (fallbackExpression != null) {
447+
shadowMatch = fallbackExpression.matchesMethodExecution(methodToMatch);
448+
}
449+
}
450+
catch (ReflectionWorldException ex4) {
451+
fallbackExpression = null;
452+
}
453+
}
454+
}
455+
}
456+
catch (IllegalStateException ex) {
457+
// AspectJ 1.8.10: encountered invalid signature
458+
logger.debug("PointcutExpression matching rejected target method", ex);
459+
fallbackExpression = null;
449460
}
450461
if (shadowMatch == null) {
451462
shadowMatch = new ShadowMatchImpl(org.aspectj.util.FuzzyBoolean.NO, null, null, null);

0 commit comments

Comments
 (0)