]> source.dussan.org Git - aspectj.git/commitdiff
Bugzilla Bug 44586
authoracolyer <acolyer>
Tue, 13 Jan 2004 16:10:52 +0000 (16:10 +0000)
committeracolyer <acolyer>
Tue, 13 Jan 2004 16:10:52 +0000 (16:10 +0000)
  After throwing advice on ctors doesn't execute for inter-type decls

tests/ajcTests.xml
tests/bugs/AfterThrowingCtor.java [new file with mode: 0644]

index a7e0c270c69dcd61436c6a94214d91c8f41139c6..4cb3a62c6918db5600339667290873618b350b09 100644 (file)
                  <message kind="error" line="8"/>
         </compile>
     </ajc-test>     
+
+    <ajc-test dir="bugs" pr="44586"
+      title="After throwing advice on ctors doesn't execute for inter-type decl field inits">
+        <compile files="AfterThrowingCtor.java">
+        </compile>
+               <run class="AfterThrowingCtor"/>
+    </ajc-test>
 </suite>
diff --git a/tests/bugs/AfterThrowingCtor.java b/tests/bugs/AfterThrowingCtor.java
new file mode 100644 (file)
index 0000000..0c21796
--- /dev/null
@@ -0,0 +1,50 @@
+// pr44586
+import org.aspectj.testing.Tester;
+public aspect AfterThrowingCtor {
+       after() throwing (Throwable t) : execution(Foo*.new(..)) {
+               throw new AdviceRanException();
+       }
+       
+       public static void main(String args[]) {
+               try {
+                       new Foo();
+                       Tester.checkFailed("Advice should not run here");
+               } catch(IllegalStateException illEx) {
+                       // good, we do not want the advice to run as the
+                       // initialization of an itd field is considered part
+                       // of the initialization join point, but not the execution
+                       // join point.
+               }
+               try {
+                       new Foo1();
+                       Tester.checkFailed("Advice should run here");
+               } catch(AdviceRanException arEx) {
+                       // good, the advice should run as the field initialisation is considered
+                       // part of the execution join point.
+               }
+       }
+
+       private Object Foo.val = Foo.initVal();
+       
+       class AdviceRanException extends RuntimeException {};
+}
+
+class Foo {
+       Foo() { 
+       }
+
+       static Object initVal() {
+               throw new IllegalStateException("crash"); 
+       }
+}
+
+class Foo1 {
+       Foo1() { 
+       }
+
+       private Object val = initVal();
+
+       static Object initVal() {
+               throw new IllegalStateException("crash"); 
+       }
+}
\ No newline at end of file