Note that there are some explanatory texts on larger screens.

plurals
  1. POModifying parameters in more than one aspect providing around advice
    primarykey
    data
    text
    <p>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 <code>joinPoint.getArgs();</code> However, it appears that each aspect gets only the original arguments; the second aspect never sees the modified values. I've contrived an example:</p> <p>The test class:</p> <pre><code>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"); } } </code></pre> <p>The method foo() is advised by two aspects:</p> <pre><code>@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); } } </code></pre> <p>and...</p> <pre><code>@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); } } </code></pre> <p>I would expect the output to be:</p> <pre><code>MooImpl is being called DoubleMooImpl is being called don't run and hide </code></pre> <p>...but is:</p> <pre><code>MooImpl is being called DoubleMooImpl is being called You should run and hide </code></pre> <p>Am I using the correct approach to modify arguments via around advice?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload