[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] If pointcut and side effects
|
Hi all,
I ran into an issues regarding combining several if pointcuts in one
and wondered if somebody could explain what seems to me like strange
behavior (the example is artificial but illustrates the point):
Say I have the following aspect:
aspect A {
pointcut p1() : call(* m(..)) && if((x=2) == 2); // last one
always true of course
before() : p1() && if(x==0) {...}
static int x = 0;
}
And a class with two methods:
void main() {
m();
}
void m() {
...
}
As expected, the advice is not executed at a call to m(), I guess
because x cannot be both 0 and 2 at the same time.
However, if I move the if(x==0) from the advice spec to a named
pointcut p2:
pointcut p2() : if(x==0);
and change the advice to:
before() : p1() && p2();
the advice executed!
I guess this is related to the side effect the if pointcut has in
changing the state value of x, but why different results in the two
cases? Is p1 and p2 evaluated independently? Which is evaluated
first? Why doesn't the assignment in p1 affect p2?
Thanks,
Jon