Community
Participate
Working Groups
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!"); } }
will fix this on Monday... simple matter of taking a defensive copy of the args before handing them out.
getArgs() now returns an Object[] with the same behaviour as arguments in a method or in advice parameters: any change to an object reference in the array is not visible outside of the advice body, but any change to the state of an argument (calling a method on a referenced arg object) is visible. Will close the defect once this fix is available in a published build.
fix now available in latest jar published from the Aspectj download page.
Fix released as part of AspectJ 1.2.1