From: acolyer Date: Mon, 9 Aug 2004 12:48:11 +0000 (+0000) Subject: fix for Bugzilla Bug 67592 value in the args[] array of thisJoinPoint can be changed.... X-Git-Tag: for_ajdt1_1_12~18 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f6436e3fc84f7e140acb3a250a29fe38f9c20c35;p=aspectj.git fix for Bugzilla Bug 67592 value in the args[] array of thisJoinPoint can be changed.... --- diff --git a/runtime/src/org/aspectj/runtime/reflect/JoinPointImpl.java b/runtime/src/org/aspectj/runtime/reflect/JoinPointImpl.java index 573d8b338..430f36a42 100644 --- a/runtime/src/org/aspectj/runtime/reflect/JoinPointImpl.java +++ b/runtime/src/org/aspectj/runtime/reflect/JoinPointImpl.java @@ -62,7 +62,12 @@ class JoinPointImpl implements JoinPoint { public Object getThis() { return _this; } public Object getTarget() { return target; } - public Object[] getArgs() { return args; } + public Object[] getArgs() { + if (args == null) { args = new Object[0]; } + Object[] argsCopy = new Object[args.length]; + System.arraycopy(args,0,argsCopy,0,args.length); + return argsCopy; + } public org.aspectj.lang.JoinPoint.StaticPart getStaticPart() { return staticPart; } diff --git a/runtime/testsrc/RuntimeModuleTests.java b/runtime/testsrc/RuntimeModuleTests.java index b8f2d7408..61bc7a869 100644 --- a/runtime/testsrc/RuntimeModuleTests.java +++ b/runtime/testsrc/RuntimeModuleTests.java @@ -16,6 +16,7 @@ import java.io.*; import org.aspectj.lang.*; +import org.aspectj.runtime.reflect.JoinPointImplTest; import org.aspectj.runtime.reflect.SignatureTest; import junit.framework.*; @@ -26,6 +27,7 @@ public class RuntimeModuleTests extends TestCase { TestSuite suite = new TestSuite(RuntimeModuleTests.class.getName()); suite.addTestSuite(RuntimeModuleTests.class); // minimum 1 test (testNothing) suite.addTestSuite(SignatureTest.class); + suite.addTestSuite(JoinPointImplTest.class); return suite; } diff --git a/runtime/testsrc/org/aspectj/runtime/reflect/JoinPointImplTest.java b/runtime/testsrc/org/aspectj/runtime/reflect/JoinPointImplTest.java new file mode 100644 index 000000000..9a2d25b82 --- /dev/null +++ b/runtime/testsrc/org/aspectj/runtime/reflect/JoinPointImplTest.java @@ -0,0 +1,40 @@ +/* + * Created on 09-Aug-2004 + * + * TODO To change the template for this generated file go to + * Window - Preferences - Java - Code Style - Code Templates + */ +package org.aspectj.runtime.reflect; + +import junit.framework.TestCase; + +/** + * @author colyer + * + * TODO To change the template for this generated type comment go to + * Window - Preferences - Java - Code Style - Code Templates + */ +public class JoinPointImplTest extends TestCase { + + public void testGetArgs() { + String arg1 = "abc"; + StringBuffer arg2 = new StringBuffer("def"); + Object arg3 = new Object(); + Object[] args = new Object[] { arg1, arg2, arg3 }; + JoinPointImpl jpi = new JoinPointImpl(null,null,null,args); + + Object[] retrievedArgs = jpi.getArgs(); + assertEquals("First arg unchanged",arg1,retrievedArgs[0]); + assertEquals("Second arg unchanged",arg2,retrievedArgs[1]); + assertEquals("Third arg unchanged",arg3,retrievedArgs[2]); + retrievedArgs[0] = "xyz"; + ((StringBuffer)retrievedArgs[1]).append("ghi"); + retrievedArgs[2] = "jkl"; + Object[] afterUpdateArgs = jpi.getArgs(); + assertEquals("Object reference not changed",arg1,afterUpdateArgs[0]); + assertEquals("Object reference unchanged",arg2,afterUpdateArgs[1]); + assertEquals("state of referenced object updated","defghi",afterUpdateArgs[1].toString()); + assertEquals("Object reference not changed",arg3,afterUpdateArgs[2]); + } + +}