Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Modifying parameters in more than one aspect providing around advice

Hi Joel,

I have just answered your question on http://stackoverflow.com/a/13084877/1082681. Copy & paste from there:

After having been on the road for days, I have finally gotten around to thinking about this and answering your question. I hope it is okay if I use native AspectJ syntax because I do not feel comfortable with the @AspectJ notation.

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface Moo {}

// ####################################

public class AspectTest {
    @Moo
    private void foo(String boo, String foo) {
        System.out.println(boo + foo);
    }

    public static void main(String[] args) {
        new AspectTest().foo("You should", " never see this");
    }
}

// ####################################

public aspect MooImpl {
    pointcut methodPointcut() : execution(@Moo * *(String, ..));

    Object around(String firstArg) : methodPointcut() && args(firstArg, ..) {
        System.out.println("MooImpl is being called");
        return proceed("don't");
    }
}

// ####################################

public aspect DoubleMooImpl {
    pointcut methodPointcut() : execution(@Moo * *(*, String, ..));

    Object around(String secondArg) : methodPointcut() && args(*, secondArg, ..) {
        System.out.println("DoubleMooImpl is being called");
        return proceed(" run and hide");
    }
}

Your mistake was to assume that you could manipulate arguments retrieved via getArgs(), which is wrong. In order to pass arguments to proceed() you need to refer to them via args(), which I have demonstrated above. Please note the syntax for retrieving the first vs. second String argument in the two aspects.

This should solve your problem.
-- 
Alexander Kriegisch
Certified Scrum Master + Professional
http://scrum-master.de


Back to the top