Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Behavior of wultiple proceeds on the same jp but different argument values

Hi -

Your advice should always say

  void around(A n, A current) ...
    proceed(current,n);

but you sometimes say

    proceed(n, current);

The code below works for me.  It has one pointcut used by multiple 
pieces of advice that advise the same join point.  Being in one
aspect, the advice run in textual order, and the target and arg
are switched as expected.

Wes

P.S. - Generally, inlining the code is best, if you can.

----------------- output
1 1 targ=1 arg=2
2 2 targ=2 arg=1
3 3 targ=1 arg=2
4 4 targ=2 arg=1
5 5 targ=1 arg=2
6 6 targ=2 arg=1

----------------- Bugs.java
public class Bugs {

    public static void main(String[] args) {
        A one = new A();
        one.x = 1;
        A two = new A();
        two.x = 2;
        one.method(two);
    }
}
class A {
    int x = 0;
    void method(A in) {        
    }
}
aspect testing implements IAspect {
    pointcut pc(A targ, A arg) : target(targ) && args(arg)
    && call(void A.method(A));
    int count;
    void log(A targ, A arg, int index) {
        System.out.print(++count + " " + index 
                + " targ=" + targ.x + " arg=" + arg.x);
        System.out.print("\n");
    }
    void around(A targ, A arg) : pc(targ, arg) {
        log(targ, arg, 1);
        proceed(arg, targ);
    }
    void around(A targ, A arg) : pc(targ, arg) {
        log(targ, arg, 2);
        proceed(arg, targ);
    }
    void around(A targ, A arg) : pc(targ, arg) {
        log(targ, arg, 3);
        proceed(arg, targ);
    }
    void around(A targ, A arg) : pc(targ, arg) {
        log(targ, arg, 4);
        proceed(arg, targ);
    }
    void around(A targ, A arg) : pc(targ, arg) {
        log(targ, arg, 5);
        proceed(arg, targ);
    }
    void around(A targ, A arg) : pc(targ, arg) {
        log(targ, arg, 6);
        proceed(arg, targ);
    }
}



> ------------Original Message------------
> From: Therapon Skotiniotis <skotthe@xxxxxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Wed, Feb-9-2005 2:36 PM
> Subject: [aspectj-users] Behavior of wultiple proceeds on the same jp but different argument values
>
> Hi all, 
> 
>  I came across some weird behavior. I have an aspect with one pcd and a 
> 
>  bunch of around advice on that pcd. e.g. 
> 
>  aspect Test { pointcut pc(A n, A current): call(* A.method(A)) && 
> args(n)
>                                   && target(current);
>                                   
> 
>           void around(A n, A current):pc(n,current){ 
>              System.out.println("around 1");
>              System.out.println("advice first arg "+ n.x);
>              System.out.println("advice second arg "+ current.x);
>              System.out.println("");
>              proceed(current,n);
>              }
> 
>   // the same advice as the one above is copied over each time 
> reversing 
>   //the values passed to proceed e.g. proceed(n,current) everytime 
> 
>   My A object has an integer field x. I have the receiver with x=0 and 
> the 
>   argument to the method "method(A)" with x = 1. 
> 
>   I expected to see a sequence of interleaving 0's and 1's. However I 
> only 
>   see the switch after 2 advice 
> 
>   I get 1,0,0,1,0,1,1,0,1,0,0,1,0,1 ... 
> 
>   So the switch happens after 2 pieces of advice get to execute. Is 
> this 
>   correct ? 
> 
>   Thanks
> 
>   -- Theo
>   PS. The code is attached 
> 




Back to the top