Project: AspectJ
Bug 67592 value in the args[] array of thisjoinpoint can be changed by one advice decl and updated values seen in another advice decl
Reported: 2004-06-17 04:06:53 | Status: resolved fixed

In ajc a use of thisJoinPoint corresponds to an object of type JoinPoint, where a JoinPoint object has four components, which can be retrieved using accessor methods. this getThis() target getTarget() args getArgs() staticJoinPoint getStaticPart() In the case of args, the object returned is an Object array. This means that an advice decl can overwrite the args, and then another advice which shares the same JoinPoint will see the changed args. Here is a small example. In this aspect the before advice changes arg[0] to always be "Laurie" and then the after advice will always say that "Laurie won a million pounds". Is this the behaviour that is intended? I would have thought that the interface to args[] should be such that the values can only be read. Otherwise very strange interactions between advice decls could occur. --------------------------------------------------------------------- public class Main { public static Main v = new Main(); void lottery ( String arg ) { System.out.println("The arg in lottery is " + arg); } public static void main (String args[]) { v.lottery("Oege"); v.lottery("Ganesh"); } } --------------------------------------------------------------------- public aspect Aspect { // This pair of advice decls demonstrates that an advice can change to // the args of a join point. before () : call(* lottery(java.lang.String)) && !within(Aspect) { System.out.println("BEFORE " + thisJoinPoint + " at " + thisJoinPointStaticPart.getSourceLocation()); Object args[] = thisJoinPoint.getArgs(); System.out.println("arg[0] is " + args[0]); args[0] = "Laurie"; System.out.println("... now it is " + thisJoinPoint.getArgs()[0]); } after () : call(* lottery(java.lang.String)) && !within(Aspect) { System.out.println("AFTER " + thisJoinPoint + " at " + thisJoinPointStaticPart.getSourceLocation()); if (thisJoinPoint.getArgs()[0].equals("Laurie")) System.out.println("Laurie wins 1 million pounds!"); } }

Files changed in fix:
runtime/src/org/aspectj/runtime/reflect/JoinPointImpl.java runtime/testsrc/RuntimeModuleTests.java runtime/testsrc/org/aspectj/runtime/reflect/JoinPointImplTest.java