Community
Participate
Working Groups
The example code in the programming guide in chapter 2 under the join points and pointcuts section and then under the pointcut composition section causes the JVM to crash due to an aspect who's advice is triggered by it's own body. The code is shown below: public class Test { public static void main(String[] args) { foo(); } static void foo() { goo(); } static void goo() { System.out.println("hi"); } } aspect A { pointcut fooPC(): execution(void Test.foo()); pointcut gooPC(): execution(void Test.goo()); pointcut printPC(): call(void java.io.PrintStream.println(String)); before(): cflow(fooPC()) && cflow(gooPC()) && printPC() { System.out.println("should occur"); } before(): cflow(fooPC() && gooPC()) && printPC() { System.out.println("should not occur"); } }
Created attachment 6283 [details] Patch to clarify documentation I propose altering the code to include an && !within(A) pointcut so that the code can execute. Also adding a section below the example with the following text and a link to the section in the documentation dealing with infinite loops caused by Aspects. This text is shown below: <para> The <literal>!within(<replaceable>A</replaceable>)</literal> pointcut above is required to avoid the <literal>printPC</literal> pointcut applying to the <literal>System.out.println</literal> call in the advice body. If this was not present a recursive call would result as the pointcut would apply to it's own advice. (See <xref linkend="pitfalls-infiniteLoops"/> for more details.) </para>
Fixed in CVS; I just (manually) applied the patch Nick very kindly provided. This was a total oversight in the documentation: The original format of that section was an email message meant to clarify composition and cflow; I never imagined anyone would want to RUN the code *smile*. -erik