From 87db1e79f6b882af30d382233589ebb1fc732be9 Mon Sep 17 00:00:00 2001 From: acolyer Date: Tue, 13 Jan 2004 16:10:52 +0000 Subject: [PATCH] Bugzilla Bug 44586 After throwing advice on ctors doesn't execute for inter-type decls --- tests/ajcTests.xml | 7 +++++ tests/bugs/AfterThrowingCtor.java | 50 +++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 tests/bugs/AfterThrowingCtor.java diff --git a/tests/ajcTests.xml b/tests/ajcTests.xml index a7e0c270c..4cb3a62c6 100644 --- a/tests/ajcTests.xml +++ b/tests/ajcTests.xml @@ -6964,4 +6964,11 @@ + + + + + + diff --git a/tests/bugs/AfterThrowingCtor.java b/tests/bugs/AfterThrowingCtor.java new file mode 100644 index 000000000..0c2179649 --- /dev/null +++ b/tests/bugs/AfterThrowingCtor.java @@ -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 -- 2.39.5