0

I'm trying to get a pointcut working.

This pointcut works:

@Around("execution(public * my.package..*ClassSuffix.*(..))")

But this pointcut does not:

@Around("execution(public * my.package..*ClassSuffix.*(..)) && !@target(my.package.NoLogging)")

The exception is

DEBUG o.s.aop.aspectj.AspectJExpressionPointcut - Could not access current invocation - matching with limited context: java.lang.IllegalStateException: No MethodInvocation found: Check that an AOP invocation is in progress, and that the ExposeInvocationInterceptor is upfront in the interceptor chain. Specifically, note that advices with order HIGHEST_PRECEDENCE will execute before ExposeInvocationInterceptor!
DEBUG o.s.aop.aspectj.AspectJExpressionPointcut - Failed to evaluate join point for arguments [] - falling back to non-match
java.lang.NullPointerException: null
        at org.aspectj.weaver.reflect.ShadowMatchImpl$RuntimeTestEvaluator.visit(ShadowMatchImpl.java:195)
        at org.aspectj.weaver.ast.HasAnnotation.accept(HasAnnotation.java:31)
        at org.aspectj.weaver.reflect.ShadowMatchImpl$RuntimeTestEvaluator.matches(ShadowMatchImpl.java:132)
        at org.aspectj.weaver.reflect.ShadowMatchImpl$RuntimeTestEvaluator.visit(ShadowMatchImpl.java:163)
        at org.aspectj.weaver.ast.Not.accept(Not.java:26)
        at org.aspectj.weaver.reflect.ShadowMatchImpl$RuntimeTestEvaluator.matches(ShadowMatchImpl.java:132)
        at org.aspectj.weaver.reflect.ShadowMatchImpl.matchesJoinPoint(ShadowMatchImpl.java:87)
        at org.springframework.aop.aspectj.AspectJExpressionPointcut.matches(AspectJExpressionPointcut.java:357)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:174)
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
        at my.package.FooClassSuffix$$EnhancerBySpringCGLIB$$e7bc07ac.doSomething(<generated>)

So it seems that the more complex pointcut requires some context, and ExposeInvocationInterceptor#invoke(..) is called at some point, but not at the right point because ExposeInvocationInterceptor#currentInvocation() throws an exception?

Is there something wrong with the pointcut? I used this as a reference: https://stackoverflow.com/a/38866088/361414

Pointcuts are defined in a class with these annotations:

@Aspect
@Component
@Order(20)
Milanka
  • 1,742
  • 19
  • 15
  • The pointcut as such looks okay, assuming you close the string as well as the annotation parenthesis at the end. There could be side effects with other pointcuts in the same aspect and/or the `@Order` in combination with other aspects/components. I am clearly lacking context here. Could you please publish an [MCVE](http://stackoverflow.com/help/mcve) reproducing the problem incl. Maven build on GitHub, please? This seems to be complex. – kriegaex Dec 12 '18 at 06:56
  • Thank you. While building the MCVE I finally noticed that the pointcut defining class also implemented `Ordered` interface, and `getOrder()` returned `Ordered.HIGHEST_PRECEDENCE`. Removing it fixed the problem. A warning about double order definition would have been nice... – Milanka Dec 13 '18 at 11:43
  • Which is exactly why I asked for an MCVE. Usually, when trying to reduce the project to the minimal version reproducing the problem, you learn something. Often you see clearer already and sometimes even find the root cause of your problem and solve it. I am glad it works for you now. :-) – kriegaex Dec 13 '18 at 14:18

0 Answers0