Community
Participate
Working Groups
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
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).
Fix released as part of AspectJ 1.2.1