Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] call and execution pointcut problem

> The problem is the usage of 'call'.

No, it is not. The problem is what I explained: You do not fully
understand how to correctly configure your build and test run in order
to achieve that the 'call' pointcut works for the test class calling the
target method. You simply need to make sure that your tests are also
woven, that is all.

> I decided to use 'execution' instead and then use StackTraceElement
> for from a stacktrace to find the calling class and method.

Think about it for a minute: Just in order to make your test work
correctly and identify the caller from the aspect, you are changing your
production aspect to manually and slowly parse a stack trace. Besides,
as soon as you introduce more aspects, you might have to adjust the
stack trace analysis, because the stack trace can change if another
aspect intercepts the same joinpoint. But even without that it is the
wrong way.

By the way, if you use 'call' in combination with
'thisEnclosingJoinPointStaticPart' (native syntax) or
'JoinPoint.EnclosingStaticPart' (annotation syntax), you can directly
determine the caller, if you need that in your aspect. Just make sure to
configure the AspectJ compiler or load time weaver to also encompass
your test class. You might want to find
https://stackoverflow.com/a/66649082/1082681 or one of my other answers
linked off of there helpful.

-- 
Alexander Kriegisch
https://scrum-master.de


Back to the top