summaryrefslogtreecommitdiffstats
path: root/tests/bugs153/pr162135/Real.java
blob: bc64ef80ca2e84e081e0bd04569e0facab621a3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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; }
}