Bug 71393 - Specify how does args pointcut collect context for pointcuts which are used in cflow
Summary: Specify how does args pointcut collect context for pointcuts which are used i...
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Docs (show other bugs)
Version: unspecified   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 1.2.1   Edit
Assignee: Erik Hilsdale CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-08-04 13:00 EDT by Lukasz Skowronski CLA
Modified: 2004-10-21 04:30 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lukasz Skowronski CLA 2004-08-04 13:00:53 EDT
This report regards collecting args by pointcut which is later used in cflow
pointcut. If that cflow is then matched more than once
in given joinpoint then which args will be exposed? (well, this situation is 
quite simple but hard to describe for me so please take a look at the 
following example)

Example (not very useful in real life but simple):

public class A {
    void doSth() {
    }

    int factor(int x) {
        doSth();
        if (x <= 1) {
            return 1;
       }
        return x * factor(x-1);
    }
    public static void main(String[] args) {
        new A().factor(11);
    }
}


public aspect AAsp {
 pointcut pc(int x) : execution(* A.factor(int)) && args(x);
 before(int x) : execution(* A.doSth()) && cflow(pc(x)) {
  System.out.println(x);
 }
}

After running this example we can see that x value is always taken from the
latest cflow match. However I can't see in specification if it is a feature
and I can rely on it.

Please define how it is supposed to work.

Regards
Luke
Comment 1 Erik Hilsdale CLA 2004-08-22 22:52:31 EDT
It is indeed supposed to work as you express.  I've added the following
section to the semantics appendix, under control flow pointcuts:

    Context exposure from control flows

    The cflow and cflowbelow pointcuts may expose context
    state through enclosed this, target, and args pointcuts.

    Anytime such state is accessed, it is accessed through
    the most recent control flow that matched. So the
    "current arg" that would be printed by the following
    program is zero, even though it is in many control
    flows.

    class Test {
        public static void main(String[] args) {
            fact(5);
        }
        static int fact(int x) {
            if (x == 0) {
                System.err.println("bottoming out");
                return 1;
            }
            else return x * fact(x - 1);
        }
    }

    aspect A {
        pointcut entry(int i): call(int fact(int)) && args(i);
        pointcut writing(): call(void println(String)) && ! within(A);

        before(int i): writing() && cflow(entry(i)) {
            System.err.println("Current arg is " + i);
        }
    }

    It is an error to expose such state through negated
    control flow pointcuts, such as within ! cflowbelow(P).

Comment 2 Adrian Colyer CLA 2004-10-21 04:30:46 EDT
Fix released as part of AspectJ 1.2.1