Bug 43891 - Example aspect A in pointcut composition section in prog guide causes recursion
Summary: Example aspect A in pointcut composition section in prog guide causes recursion
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Docs (show other bugs)
Version: 1.2   Edit
Hardware: All All
: P3 minor (vote)
Target Milestone: 1.2   Edit
Assignee: Erik Hilsdale CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-09-30 03:04 EDT by Nick Brett CLA
Modified: 2012-04-03 16:11 EDT (History)
0 users

See Also:


Attachments
Patch to clarify documentation (1.31 KB, patch)
2003-09-30 03:09 EDT, Nick Brett CLA
aclement: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Brett CLA 2003-09-30 03:04:51 EDT
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");
    }
}
Comment 1 Nick Brett CLA 2003-09-30 03:09:24 EDT
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>
Comment 2 Erik Hilsdale CLA 2003-11-17 22:49:36 EST
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