Community
Participate
Working Groups
See the attached source for example source to recreate the issue. In the source, I have a class that has a method, "innerMethod," which is advised based upon my own annotation, "Test". When "innerMethod" is called by another method within the same class, "outerMethod," in the below class, the advise ends up getting called twice even though the outer method is not advised. The source includes the build.xml file that I used to build the source to reproduce the problem.
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!