]> source.dussan.org Git - aspectj.git/commitdiff
162135: test and fix
authoraclement <aclement>
Thu, 4 Dec 2008 23:39:08 +0000 (23:39 +0000)
committeraclement <aclement>
Thu, 4 Dec 2008 23:39:08 +0000 (23:39 +0000)
tests/bugs153/pr162135/Foo.java
tests/bugs153/pr162135/Foo6.java [new file with mode: 0644]
tests/bugs153/pr162135/Real.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java
tests/src/org/aspectj/systemtest/ajc153/ajc153.xml

index df4211a4b180c0cd3a233081bda0a6bbaad963cc..0d408e3c8c25bdb54f4a783aa881dc8361a25ad8 100644 (file)
@@ -6,15 +6,19 @@ import org.aspectj.lang.annotation.Pointcut;
 
 @Aspect public class Foo {
 
+ static class X {
   public void m() {
     new RuntimeException("hello");
   }
+ }
        
   public static void main(String[] argv) {
+           new X().m();
   }
                
   @Pointcut("call(Throwable+.new(String, ..)) && this(caller) && if()")
   public static boolean exceptionInitializer(Object caller) {
+      System.out.println("In if(), is there a caller? "+(caller!=null?"yes":"no"));
       return true;
   }
 
diff --git a/tests/bugs153/pr162135/Foo6.java b/tests/bugs153/pr162135/Foo6.java
new file mode 100644 (file)
index 0000000..16f125e
--- /dev/null
@@ -0,0 +1,30 @@
+import java.lang.reflect.Field;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Pointcut;
+
+@Aspect public class Foo6 {
+
+  public void m() {
+    new RuntimeException("hello");
+  }
+       
+  public static void main(String[] argv) {
+         try {
+          new Foo6().m();
+         } catch (Throwable t) {}
+  }
+               
+  @Pointcut("call(Throwable+.new(String, ..)) && this(caller) && if()")
+  public static boolean exceptionInitializer(Object caller) {
+      return true;
+  }
+
+  @Around("exceptionInitializer(caller)")
+  public Object annotateException(ProceedingJoinPoint jp, Object caller) {
+      System.out.println("ProceedingJoinPoint is "+jp);
+      System.out.println("caller is "+(caller==null?"null":"notnull"));
+      return null;
+  }
+}
diff --git a/tests/bugs153/pr162135/Real.java b/tests/bugs153/pr162135/Real.java
new file mode 100644 (file)
index 0000000..bc64ef8
--- /dev/null
@@ -0,0 +1,47 @@
+package a.b.c;
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Pointcut;
+
+
+class Foo {
+  public void m() {
+         throw new RuntimeException("Hello World");
+  }
+
+
+}
+@Aspect
+public class Real {
+
+  public static void main(String []argv) {
+         try {
+         new Foo().m();
+         } catch (Throwable t) {
+                System.out.println(t.getMessage());
+         }
+  }
+
+    @Pointcut("call(Throwable+.new(String, ..)) && this(caller) && args(exceptionMessage) && if()")
+    public static boolean exceptionInitializer(Object caller, String exceptionMessage) {
+        return isNdcEmpty();
+    }
+
+    @Around("exceptionInitializer(caller, exceptionMessage)")
+    public Object annotateException(ProceedingJoinPoint jp, Object caller, String exceptionMessage) {
+       System.out.println("advice running");
+        return jp.proceed(new Object[]{caller, "newmessage"});
+    }
+
+    private static boolean isNdcEmpty() {
+        return NDC.getDepth() == 0;
+    }
+
+}
+
+
+class NDC {
+  public static int getDepth() { return 0; }
+}
index 1d4f30ac0d18f4bacdc4a737aad5fcecaa90687f..5fca46ebf5cdc23878a06a52454538befe0f11b2 100644 (file)
@@ -34,11 +34,34 @@ public class Ajc153Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
        // public void testCFlowXMLAspectLTW_pr149096() { runTest("cflow xml concrete aspect"); }
        // public void testAmbiguousBinding_pr121805() { runTest("ambiguous binding");}
        // public void testNegatedAnnotationMatchingProblem_pr153464() { runTest("negated annotation matching problem");}
-       // public void testAnnotationStyleBcException_pr162135() { runTest("bcexception in annotation style around advice");}
-       // public void testAnnotationStyleBcException_pr162135_2() { runTest("bcexception in annotation style around advice - 2");}
-       // public void testAnnotationStyleBcException_pr162135_3() { runTest("bcexception in annotation style around advice - 3");}
-       // public void testAnnotationStyleBcException_pr162135_4() { runTest("bcexception in annotation style around advice - 4");}
-       // public void testAnnotationStyleBcException_pr162135_5() { runTest("bcexception in annotation style around advice - 5");}
+       public void testAnnotationStyleBcException_pr162135() {
+               runTest("bcexception in annotation style around advice");
+       }
+
+       public void testAnnotationStyleBcException_pr162135_2() {
+               runTest("bcexception in annotation style around advice - 2");
+       }
+
+       public void testAnnotationStyleBcException_pr162135_3() {
+               runTest("bcexception in annotation style around advice - 3");
+       }
+
+       public void testAnnotationStyleBcException_pr162135_4() {
+               runTest("bcexception in annotation style around advice - 4");
+       }
+
+       public void testAnnotationStyleBcException_pr162135_5() {
+               runTest("bcexception in annotation style around advice - 5");
+       }
+
+       public void testAnnotationStyleBcException_pr162135_6() {
+               runTest("bcexception in annotation style around advice - 6");
+       }
+
+       public void testAnnotationStyleBcException_pr162135_7() {
+               runTest("bcexception in annotation style around advice - 7");
+       }
+
        public void testIncompatibleClassChangeWithITD_pr164633() {
                runTest("incompatibleclasschange");
        }
index 1b235854eba4d341f1181ca70b0ada54a109fc8c..a74742c710804d8bbf5c6560747abfdb3112e834 100644 (file)
 
     <ajc-test dir="bugs153/pr162135" title="bcexception in annotation style around advice">
       <compile files="Foo.java" options="-1.5"/>
-      <run class="Foo"/>
+      <run class="Foo">
+        <stdout>
+          <line text="In if(), is there a caller? yes"/>
+        </stdout>
+      </run>
     </ajc-test>
 
     <ajc-test dir="bugs153/pr162657" title="complex pointcut">
       <compile files="Foo5.java" options="-1.5"/>
       <run class="Foo5"/>
     </ajc-test>
+
+    <ajc-test dir="bugs153/pr162135" title="bcexception in annotation style around advice - 6">
+      <compile files="Foo6.java" options="-1.5"/>
+      <run class="Foo6">
+      <stdout>
+      <line text="ProceedingJoinPoint is call(java.lang.RuntimeException(String))"/>
+      <line text="caller is notnull"/>
+      </stdout>
+      </run>
+    </ajc-test>
+    
+    <ajc-test dir="bugs153/pr162135" title="bcexception in annotation style around advice - 7">
+      <compile files="Real.java" options="-1.5"/>
+      <run class="a.b.c.Real">
+      <stdout>
+      <line text="advice running"/>
+      <line text="newmessage"/>
+      </stdout>
+      </run>
+    </ajc-test>
     
      <ajc-test dir="bugs153/pr159143" title="declare method annotations">
         <compile files="DeclareMethodAnnotation.java" options="-1.5">