]> source.dussan.org Git - aspectj.git/commitdiff
test and fix for 116626 from Matthew.
authoraclement <aclement>
Fri, 18 Nov 2005 09:01:17 +0000 (09:01 +0000)
committeraclement <aclement>
Fri, 18 Nov 2005 09:01:17 +0000 (09:01 +0000)
tests/bugs150/pr116626/TestAspect.aj [new file with mode: 0644]
tests/bugs150/pr116626/aop.xml [new file with mode: 0644]
tests/bugs150/pr116626/com/foo/bar/Test.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java
tests/src/org/aspectj/systemtest/ajc150/ajc150.xml
weaver/src/org/aspectj/weaver/tools/WeavingAdaptor.java

diff --git a/tests/bugs150/pr116626/TestAspect.aj b/tests/bugs150/pr116626/TestAspect.aj
new file mode 100644 (file)
index 0000000..105a53e
--- /dev/null
@@ -0,0 +1,19 @@
+package com.foo.bar;
+
+public privileged aspect TestAspect {
+
+      pointcut TestToArray(Test mt) :
+                target(mt) &&
+                !within(TestAspect);
+
+
+    Object[] around(Test mt, Object[] objs) :
+            TestToArray(mt) &&
+            args(objs) &&
+            execution(Object[] Test.getObjs(Object[])) {
+
+        objs = proceed(mt, objs);
+        System.out.println("GO Aspects!");
+        return objs;
+    }
+}
diff --git a/tests/bugs150/pr116626/aop.xml b/tests/bugs150/pr116626/aop.xml
new file mode 100644 (file)
index 0000000..93ca6dd
--- /dev/null
@@ -0,0 +1,9 @@
+<aspectj>
+       <aspects>
+               <aspect name="com.foo.bar.TestAspect"/>
+       </aspects>
+
+       <weaver options="-verbose -XlazyTjp -showWeaveInfo">
+               <include within="com.foo.*"/>
+       </weaver>
+</aspectj>
diff --git a/tests/bugs150/pr116626/com/foo/bar/Test.java b/tests/bugs150/pr116626/com/foo/bar/Test.java
new file mode 100644 (file)
index 0000000..5b255ba
--- /dev/null
@@ -0,0 +1,28 @@
+package com.foo.bar;
+
+import java.util.*;
+
+public class Test<T> {
+
+       Set<T> intsSet;
+
+       public Test() {
+               this.intsSet = new HashSet<T>();
+       }
+
+       public <T> T[] getObjs(T[] a) {
+               return intsSet.toArray(a);
+       }
+
+       public static void main(String[] args) {
+               System.out.println("AAA :-)");
+               new TTT().foo();
+       }
+}
+
+class TTT {
+       public void foo() {
+               Test<Object> mt = new Test<Object>();
+               Object[] arr = mt.getObjs(new Object[]{});
+       }
+}
index eab3ffac624c8699f2cee7985ef8ac5e53a535b1..08209ca26b1bdee0089395b24c83f20ac685f52e 100644 (file)
@@ -712,6 +712,11 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
   public void testNoStackOverflowWithCircularPCDInGenericAspect2() {
          runTest("no StackOverflowError with circular pcd in generic aspect - 2");
   }
+
+  /*
+   * Load-time weaving bugs
+   */
+  public void testNPEinWeavingAdaptor_pr116626() { runTest("NPE in WeavingAdaptor");}
   
   // helper methods.....
   
index a2075580f988f2d0ac17958d48de5c26d9c54795..de7cf19d2d92da08d9324863866a292a8922e364 100644 (file)
    <ajc-test dir="java5/generics/itds/design" title="generic itds - design G">
      <compile files="DesignG.java" options="-1.5"/>
    </ajc-test>
+   
+   <ajc-test dir="bugs150/pr116626" title="NPE in WeavingAdaptor">
+     <compile files="com/foo/bar/Test.java, TestAspect.aj" options="-1.5"/>
+     <run class="com.foo.bar.Test" ltw="aop.xml"
+     >
+     </run>
+   </ajc-test>
 
 </suite>
\ No newline at end of file
index ea75902738c27222381e1fae587a6e6d4713686a..6d11ff3077b6c9dfb736529ca8dfbcf4fb61cf48 100644 (file)
@@ -387,14 +387,15 @@ public class WeavingAdaptor {
 
        private class WeavingClassFileProvider implements IClassFileProvider {
 
+               private UnwovenClassFile unwovenClass;
                private List unwovenClasses = new ArrayList(); /* List<UnovenClassFile> */
                private UnwovenClassFile wovenClass;
         private boolean isApplyAtAspectJMungersOnly = false;
 
         public WeavingClassFileProvider (String name, byte[] bytes) {
-                       UnwovenClassFile unwoven = new UnwovenClassFile(name,bytes);
-                       unwovenClasses.add(unwoven);
-                       bcelWorld.addSourceObjectType(unwoven.getJavaClass());
+                       this.unwovenClass = new UnwovenClassFile(name,bytes);
+                       this.unwovenClasses.add(unwovenClass);
+                       bcelWorld.addSourceObjectType(unwovenClass.getJavaClass());
                }
 
         public void setApplyAtAspectJMungersOnly() {
@@ -406,7 +407,8 @@ public class WeavingAdaptor {
         }
 
         public byte[] getBytes () {
-                       return wovenClass.getBytes();
+               if (wovenClass != null) return wovenClass.getBytes();
+               else return unwovenClass.getBytes();
                }
 
                public Iterator getClassFileIterator() {