Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] If pointcut and side effects

> Is p1 and p2 evaluated independently? Which is evaluated  
> first? Why doesn't the assignment in p1 affect p2?

>From the programming guide, semantics appendix discussion of
the if pointcut:

  Note that the order of evaluation for pointcut expression 
  components at a join point is undefined. Writing if pointcuts 
  that have side-effects is considered bad style and may also 
  lead to potentially confusing or even changing behavior with 
  regard to when or if the test code will run.

It can be confusing because programmers come to rely on the
order of evaluation for boolean expressions in Java, but 
these aren't that.

Wes

> ------------Original Message------------
> From: "Jon S. Baekken" <jbaekken@xxxxxxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Tue, May-30-2006 2:08 PM
> Subject: [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
> 
> 
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
> 



Back to the top