From 6d7cd9c7dc94dc55af9a8c4fba3171fedf5931b7 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 23 May 2024 17:07:51 +0200 Subject: [PATCH] Defensive handling of incompatible advice methods This covers AspectJ transaction and caching aspects when encountered by Spring AOP. Closes gh-32882 See gh-32793 --- .../annotation/ReflectiveAspectJAdvisorFactory.java | 12 ++++++++++-- .../aop/aspectj/autoproxy/ajcAutoproxyTests.xml | 6 ++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java index 90cc3880cb..e4eec7a919 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/ReflectiveAspectJAdvisorFactory.java @@ -213,8 +213,16 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto return null; } - return new InstantiationModelAwarePointcutAdvisorImpl(expressionPointcut, candidateAdviceMethod, - this, aspectInstanceFactory, declarationOrderInAspect, aspectName); + try { + return new InstantiationModelAwarePointcutAdvisorImpl(expressionPointcut, candidateAdviceMethod, + this, aspectInstanceFactory, declarationOrderInAspect, aspectName); + } + catch (IllegalArgumentException | IllegalStateException ex) { + if (logger.isDebugEnabled()) { + logger.debug("Ignoring incompatible advice method: " + candidateAdviceMethod, ex); + } + return null; + } } @Nullable diff --git a/spring-aspects/src/test/resources/org/springframework/aop/aspectj/autoproxy/ajcAutoproxyTests.xml b/spring-aspects/src/test/resources/org/springframework/aop/aspectj/autoproxy/ajcAutoproxyTests.xml index 63d6e15591..bc5e5258f8 100644 --- a/spring-aspects/src/test/resources/org/springframework/aop/aspectj/autoproxy/ajcAutoproxyTests.xml +++ b/spring-aspects/src/test/resources/org/springframework/aop/aspectj/autoproxy/ajcAutoproxyTests.xml @@ -2,15 +2,21 @@ + + + +