]> source.dussan.org Git - aspectj.git/commitdiff
fix for Bugzilla Bug 67592 value in the args[] array of thisJoinPoint can be changed....
authoracolyer <acolyer>
Mon, 9 Aug 2004 12:48:11 +0000 (12:48 +0000)
committeracolyer <acolyer>
Mon, 9 Aug 2004 12:48:11 +0000 (12:48 +0000)
runtime/src/org/aspectj/runtime/reflect/JoinPointImpl.java
runtime/testsrc/RuntimeModuleTests.java
runtime/testsrc/org/aspectj/runtime/reflect/JoinPointImplTest.java [new file with mode: 0644]

index 573d8b338471a17b01fc855c870b762b95faa32c..430f36a4248984a1a3a75f7f1b97f79f7372bddf 100644 (file)
@@ -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; }
 
index b8f2d7408ff2236b4e74f75e1df8c709f2865195..61bc7a86950ee13a5f10ad94505de6782350127f 100644 (file)
@@ -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 (file)
index 0000000..9a2d25b
--- /dev/null
@@ -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]);
+       }
+       
+}