Project: AspectJ
Bug 44586 After throwing advice on ctors doesn't execute for inter-type decls
Reported: 2003-10-09 13:53:43 | Status: resolved fixed

The following code doesn't work in Ajc 1.1.1, in Ajc built from CVS HEAD (as of yesterday), nor in Ajc 1.0.6: Output: C:\devel\test\excHandling>java AfterThrowingCtor Exception in thread "main" java.lang.IllegalStateException: crash at Foo.initVal(AfterThrowingCtor.java:21) at AfterThrowingCtor.ajc$interFieldInit$AfterThrowingCtor$Foo$val (AfterT hrowingCtor.java:9) at Foo.<init>(AfterThrowingCtor.java:13) at AfterThrowingCtor.main(AfterThrowingCtor.java:6) Correct Output: threw java.lang.IllegalStateException: crash at execution(Foo()) Exception in thread "main" java.lang.IllegalStateException: crash at Foo.initVal(AfterThrowingCtor.java:21) at AfterThrowingCtor.ajc$interFieldInit$AfterThrowingCtor$Foo$val (AfterT hrowingCtor.java:9) at Foo.<init>(AfterThrowingCtor.java:13) at AfterThrowingCtor.main(AfterThrowingCtor.java:6) Input source: public aspect AfterThrowingCtor { after() throwing (Throwable t) : execution(Foo.new(..)) { System.err.println("threw "+t+" at "+thisJoinPointStaticPart); } public static void main(String args[]) { new Foo(); } private Object Foo.val = Foo.initVal(); } class Foo { Foo() { } // if you uncomment this line and comment out the inter-type decl. // the advice runs correctly //private Object val = initVal(); static Object initVal() { throw new IllegalStateException("crash"); } } --- AspectJ 1.1.1 runs the after throwing advice correctly if the field is declared normally (AspectJ 1.0.6 fails to do even this).

Files changed in fix:
tests/bugs/AfterThrowingCtor.java