From 5834de97836ebcc056415736c17c46e8b1dfaf5a Mon Sep 17 00:00:00 2001 From: jhugunin Date: Wed, 14 Jan 2004 15:24:06 +0000 Subject: Fix for Bugzilla Bug 44587 Erroneous exception conversion and Bugzilla Bug 34206 before():execution(new(..)) does not throw NoAspectBoundException All exceptions that occur during the static intialization of a persingleton aspect will be swallowed. When using that aspect (via aspectOf()) a NoAspectBoundException will be thrown with the original exception from the staitc initializer as the cause. --- tests/bugs/ErroneousExceptionConversion.java | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/bugs/ErroneousExceptionConversion.java (limited to 'tests/bugs/ErroneousExceptionConversion.java') diff --git a/tests/bugs/ErroneousExceptionConversion.java b/tests/bugs/ErroneousExceptionConversion.java new file mode 100644 index 000000000..13db17a18 --- /dev/null +++ b/tests/bugs/ErroneousExceptionConversion.java @@ -0,0 +1,44 @@ +// pr 44587 +import org.aspectj.testing.Tester; +import org.aspectj.lang.NoAspectBoundException; +public class ErroneousExceptionConversion { + + public static void main(String[] args) { + try { + new ErroneousExceptionConversion(); + Tester.checkFailed("Wanted an exception in initializer error"); + } catch (NoAspectBoundException nabEx) { + // good + // check nabEx.getCause instanceof RuntimeException and has explanation "boom..." + Throwable cause = nabEx.getCause(); + if (!(cause instanceof RuntimeException)) { + Tester.checkFailed("Should have a RuntimeException as cause"); + } + } catch(Throwable t) { + Tester.checkFailed("Wanted an ExceptionInInitializerError but got " + t); + } + } + + +} + +aspect A { + + int ErroneousExceptionConversion.someField = throwIt(); + + public static int throwIt() { + throw new RuntimeException("Exception during aspect initialization"); + } + + public A() { + System.err.println("boom in 5..."); + throw new RuntimeException("boom"); + } + + // if I change this to execution the test passes... + after() throwing : initialization(ErroneousExceptionConversion.new(..)) { + System.out.println("After throwing"); + } + +} + -- cgit v1.2.3