Summary: | Advice called twice when advised method called from outer method in same class | ||||||
---|---|---|---|---|---|---|---|
Product: | [Tools] AspectJ | Reporter: | Scott Hirdes <scott.hirdes> | ||||
Component: | Compiler | Assignee: | aspectj inbox <aspectj-inbox> | ||||
Status: | RESOLVED INVALID | QA Contact: | |||||
Severity: | normal | ||||||
Priority: | P3 | CC: | aclement | ||||
Version: | 1.6.4 | ||||||
Target Milestone: | --- | ||||||
Hardware: | PC | ||||||
OS: | Linux | ||||||
URL: | http://www.jivesoftware.com | ||||||
Whiteboard: | |||||||
Attachments: |
|
Description
Scott Hirdes
2009-05-04 12:55:39 EDT
Created attachment 134268 [details]
Example project to recreate duplicate call to advice
Should have had this my initial post.
Here is the output of running the provided example program:
> scott@ipswitch:/media/data/code/aspectjrecreate/target$ java -cp $MYTEST > com.mytest.ExecuteTest
> In the aspect
> In the aspect
> Hello world!
See the "In the aspect" string is output twice.
Hi.
Because you didn't specify a kind of join point, you got both join points advised for the method invocation. On -showWeaveInfo we can see that both method-call and method-execution for innerMethod got advised:
>ajc -1.5 -showWeaveInfo *.java *.aj
Join point 'method-call(void com.mytest.ExecuteTest.innerMethod(java.lang.String))' in Type 'com.mytest.ExecuteTest' (ExecuteTest.java:13) advised by before advice from 'com.mytest.TestAspect' (TestAspect.aj:7)
Join point 'method-execution(void com.mytest.ExecuteTest.innerMethod(java.lang.String))' in Type 'com.mytest.ExecuteTest' (ExecuteTest.java:17) advised by before advice from 'com.mytest.TestAspect' (TestAspect.aj:7)
Hence the advise firing twice. It is invoked at the point where the method is invoked (so in outerMethod()) and then again from the method body (in innerMethod()). I suspect you just wanted the method-execution join point. So I would change the pointcut to:
before() : execution(@com.mytest.Test * *(..)) {
You will also find that including the annotation in the execution() pointcut signature is more performant than using @annotation().
Thanks for the resolution to this! |