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 d9a72b6417f1..c1a0ee650428 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -334,13 +334,15 @@ public boolean matches(Method method, Class targetClass, Object... args) { Object targetObject = null; Object thisObject = null; try { - MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation(); - targetObject = mi.getThis(); - if (!(mi instanceof ProxyMethodInvocation _pmi)) { - throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); + MethodInvocation curr = ExposeInvocationInterceptor.currentInvocation(); + if (curr.getMethod() == method) { + targetObject = curr.getThis(); + if (!(curr instanceof ProxyMethodInvocation currPmi)) { + throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + curr); + } + pmi = currPmi; + thisObject = pmi.getProxy(); } - pmi = _pmi; - thisObject = pmi.getProxy(); } catch (IllegalStateException ex) { // No current invocation...