]> source.dussan.org Git - aspectj.git/commitdiff
fix for Bugzilla Bug 72150
authoraclement <aclement>
Fri, 27 Aug 2004 10:03:54 +0000 (10:03 +0000)
committeraclement <aclement>
Fri, 27 Aug 2004 10:03:54 +0000 (10:03 +0000)
   AJC possible bug with static nested classes

tests/bugs/java5/arrayCloning/A.java [new file with mode: 0644]
tests/bugs/java5/arrayCloning/C.java [new file with mode: 0644]
tests/bugs/java5/arrayCloning/OneFiveCode.jar [new file with mode: 0644]
tests/bugs/java5/arrayCloning/explanation.txt [new file with mode: 0644]
tests/bugs/java5/arrayCloning/rebuild.bat [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc121/Ajc121Tests.java
tests/src/org/aspectj/systemtest/ajc121/ajc121-tests.xml
weaver/src/org/aspectj/weaver/TypeX.java

diff --git a/tests/bugs/java5/arrayCloning/A.java b/tests/bugs/java5/arrayCloning/A.java
new file mode 100644 (file)
index 0000000..10cb713
--- /dev/null
@@ -0,0 +1,6 @@
+aspect A {
+  Object around(): call(* clone(..)) {
+    return proceed();
+  }
+}
+
diff --git a/tests/bugs/java5/arrayCloning/C.java b/tests/bugs/java5/arrayCloning/C.java
new file mode 100644 (file)
index 0000000..8886906
--- /dev/null
@@ -0,0 +1,41 @@
+import java.lang.reflect.*;
+
+class C {
+
+  public static B.D[] arr = new B.D[5];
+
+  public static void main(String[]argv) {
+    arr[0] = new B.D(42);
+    arr[1] = new B.D(22);
+    arr[2] = new B.D(46);
+    arr[3] = new B.D(50);
+    arr[4] = new B.D(54);
+
+    B.D[] arr2 = arr.clone();
+
+
+    // Check the clone is OK
+    if (arr2[0].i!=42) throw new RuntimeException("Call that a clone 0");
+    if (arr2[1].i!=22) throw new RuntimeException("Call that a clone 1");
+    if (arr2[2].i!=46) throw new RuntimeException("Call that a clone 2");
+    if (arr2[3].i!=50) throw new RuntimeException("Call that a clone 3");
+    if (arr2[4].i!=54) throw new RuntimeException("Call that a clone 4");
+    System.err.println("Clone OK - attempting value manipulation");
+
+    // Change the clone, check the original is OK
+    arr2[2] = new B.D(1);
+    if (arr[2].i == 1)  throw new RuntimeException("Shouldnt have affected original");
+    if (arr2[2].i != 1) throw new RuntimeException("Should have affected clone");
+
+
+    System.err.println("Clone OK - finished");
+  }
+}
+
+
+class B {
+  public static class D {
+    public int i;
+    D(int x) { i=x;}
+  }
+}
diff --git a/tests/bugs/java5/arrayCloning/OneFiveCode.jar b/tests/bugs/java5/arrayCloning/OneFiveCode.jar
new file mode 100644 (file)
index 0000000..0196f39
Binary files /dev/null and b/tests/bugs/java5/arrayCloning/OneFiveCode.jar differ
diff --git a/tests/bugs/java5/arrayCloning/explanation.txt b/tests/bugs/java5/arrayCloning/explanation.txt
new file mode 100644 (file)
index 0000000..b3f4de2
--- /dev/null
@@ -0,0 +1,2 @@
+Under Java 1.4 the target of a clone() method called on an array type was 'Object.clone' in the byte code.
+Under Java 1.5 this has been changed to be (correctly) a call to the clone() method on the array type.
\ No newline at end of file
diff --git a/tests/bugs/java5/arrayCloning/rebuild.bat b/tests/bugs/java5/arrayCloning/rebuild.bat
new file mode 100644 (file)
index 0000000..f0004a9
--- /dev/null
@@ -0,0 +1,4 @@
+erase *.class\r
+javac C.java\r
+jar -cvMf OneFiveCode.jar *.class\r
+erase *.class\r
index bdd7521605bb045922c32987e82d5839c3afaa33..7c3e3a26198d9d093424644d48a5738edb221c67 100644 (file)
@@ -267,5 +267,9 @@ public class Ajc121Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
   public void test050_typePatternMatchingWithArrays() {
        runTest("declare warning warns at wrong points");
   }
+
+  public void test051_arrayCloningInJava5() {
+    runTest("AJC possible bug with static nested classes");
+  }
 }
 
index edf21cf949227e9d5985106362b5048759640699..dd966429518544554493fb8f299e63811a833a96 100644 (file)
                        <message kind="warning" line="22" text="*[] returning method called"/>
                </compile>
        </ajc-test>
+       
+       <ajc-test dir="bugs/java5/arrayCloning" pr="72150"
+          title="AJC possible bug with static nested classes">
+          <compile files="A.java" inpath="OneFiveCode.jar"/>
+          <!--run class="C"/-->
+    </ajc-test>
        
\ No newline at end of file
index b871d721b113fd1136dab4f4e7a43e9ae113eedc..eb0ec35b4652caeae9213bf10cca9f28571f3c51 100644 (file)
@@ -583,8 +583,13 @@ public class TypeX {
         if (name.equals("void")) return "V";
         if (name.endsWith("[]")) 
             return "[" + nameToSignature(name.substring(0, name.length() - 2));
-        if (name.length() != 0)  // lots more tests could be made here...
-            return "L" + name.replace('.', '/') + ";";
+        if (name.length() != 0) {
+               // lots more tests could be made here...
+               
+               // 1) If it is already an array type, do not mess with it.
+               if (name.charAt(0)=='[' && name.charAt(name.length()-1)==';') return name;
+               else return "L" + name.replace('.', '/') + ";";
+        }
         else 
             throw new BCException("Bad type name: " + name);
     }