[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] Modifying parameters in more than one aspect providing around advice
|
Hello list members,
I have two aspects each of which modify method arguments. When both
aspects are applied to the same method, I would expect execution of
the aspects to be chained and I would expect that the arguments
modified in the first aspect to be available to the second aspect via
joinPoint.getArgs(); However, it appears that each aspect gets only
the original arguments; the second aspect never sees the modified
values. I've contrived an example:
The test class:
public class AspectTest extends TestCase {
@Moo
private void foo(String boo, String foo) {
System.out.println(boo + foo);
}
public void testAspect() {
foo("You should", " never see this");
}
}
The method foo() is advised by two aspects:
@Aspect
public class MooImpl {
@Pointcut("execution(@Moo * *(..))")
public void methodPointcut() {}
@Around("methodPointcut()")
public Object afterMethodInControllerClass(ProceedingJoinPoint
joinPoint) throws Throwable {
System.out.println("MooImpl is being called");
Object[] args = joinPoint.getArgs();
args[0] = "don't";
return joinPoint.proceed(args);
}
}
and...
@Aspect
public class DoubleMooImpl {
@Pointcut("execution(@Moo * *(..))")
public void methodPointcut() {}
@Around("methodPointcut()")
public Object afterMethodInControllerClass(ProceedingJoinPoint
joinPoint) throws Throwable {
System.out.println("DoubleMooImpl is being called");
Object[] args = joinPoint.getArgs();
args[1] = " run and hide";
return joinPoint.proceed(args);
}
}
I would expect the output to be:
MooImpl is being called
DoubleMooImpl is being called
don't run and hide
...but is:
MooImpl is being called
DoubleMooImpl is being called
You should run and hide
Am I using the correct approach to modify arguments via around advice?
Note I have asked this question on Stack Overflow. Interested peeps
can find it here:
http://stackoverflow.com/questions/12843998/modifying-parameters-in-more-than-one-aspect-providing-around-advice
Thanks for taking the time to read this!