@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;
}
--- /dev/null
+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;
+ }
+}
--- /dev/null
+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; }
+}
// 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");
}
<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">