diff options
author | jhugunin <jhugunin> | 2004-01-14 15:24:06 +0000 |
---|---|---|
committer | jhugunin <jhugunin> | 2004-01-14 15:24:06 +0000 |
commit | 5834de97836ebcc056415736c17c46e8b1dfaf5a (patch) | |
tree | a7b87ccc35e25aafe73d24d17f08cc33f62b22c4 /tests | |
parent | 7bbd1f419239dc9e8b46e7fd912b2bc007bbd76a (diff) | |
download | aspectj-5834de97836ebcc056415736c17c46e8b1dfaf5a.tar.gz aspectj-5834de97836ebcc056415736c17c46e8b1dfaf5a.zip |
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.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ajcTests.xml | 14 | ||||
-rw-r--r-- | tests/bugs/ErroneousExceptionConversion.java | 44 | ||||
-rw-r--r-- | tests/bugs/ErroneousExceptionConversion1.java | 26 | ||||
-rw-r--r-- | tests/new/ConstructorExecInitFails.java | 6 |
4 files changed, 89 insertions, 1 deletions
diff --git a/tests/ajcTests.xml b/tests/ajcTests.xml index 6a68bc4a6..e07ae9507 100644 --- a/tests/ajcTests.xml +++ b/tests/ajcTests.xml @@ -7092,4 +7092,18 @@ <run class="Main1"/> </ajc-test> + <ajc-test dir="bugs" pr="44587" + title="Erroneous exception conversion"> + <compile files="ErroneousExceptionConversion.java"> + </compile> + <run class="ErroneousExceptionConversion"/> + </ajc-test> + + <ajc-test dir="bugs" pr="34206" + title="before():execution(new(..)) does not throw NoAspectBoundException"> + <compile files="ErroneousExceptionConversion1.java"> + </compile> + <run class="ErroneousExceptionConversion1"/> + </ajc-test> + </suite> 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"); + } + +} + diff --git a/tests/bugs/ErroneousExceptionConversion1.java b/tests/bugs/ErroneousExceptionConversion1.java new file mode 100644 index 000000000..9a8f0e2ab --- /dev/null +++ b/tests/bugs/ErroneousExceptionConversion1.java @@ -0,0 +1,26 @@ +import org.aspectj.lang.*; +import org.aspectj.testing.Tester; + +aspect Watchcall { + pointcut myConstructor(): execution(new(..)); + + before(): myConstructor() { + System.err.println("Entering Constructor"); + } + + after(): myConstructor() { + System.err.println("Leaving Constructor"); + } +} + +public class ErroneousExceptionConversion1 { + public static void main(String[] args) { + try { + ErroneousExceptionConversion1 c = new ErroneousExceptionConversion1(); + Tester.checkFailed("shouldn't get here"); + } catch (NoAspectBoundException nab) { + // expected + } + + } +} diff --git a/tests/new/ConstructorExecInitFails.java b/tests/new/ConstructorExecInitFails.java index 4b5e775e4..e042f10ff 100644 --- a/tests/new/ConstructorExecInitFails.java +++ b/tests/new/ConstructorExecInitFails.java @@ -1,4 +1,5 @@ import org.aspectj.testing.*; +import org.aspectj.lang.*; /** * -usejavac mode: no error @@ -8,7 +9,10 @@ public class ConstructorExecInitFails { public static void main(String[] args) { try { new ConstructorExecInitFails(); - } catch (ExceptionInInitializerError e) { + } catch (NoAspectBoundException e) { + + Tester.check(e.getCause() instanceof NoAspectBoundException, + "Expected NoAspectBoundException, found " + e.getCause()); return; } Tester.checkFailed("shouldn't be able to run"); |