diff options
| author | 2015-04-22 18:10:36 -0700 | |
|---|---|---|
| committer | 2015-04-22 18:10:36 -0700 | |
| commit | bfdcdc1e2c0af34aeaf7b5b4d499975e0c3157be (patch) | |
| tree | 17143f52b438284477fa6e3ac8fe74b0d82a5744 /test/008-exceptions/src/Main.java | |
| parent | 8e58d76eb30a50e38c46bd6277186116937ba396 (diff) | |
ART: Fix re-throwing failures of non-convention errors
While it is convention that Throwable subclasses should have a
constructor with a String argument, that is not rigorously enforced.
So if a static initializer throws an error that omits that
constructor, we must not provide a message when trying to throw
again.
Bug: 20495321
Bug: 20497840
Change-Id: Ia4334fa24223750f90a8f2732f1eb1e738575e8d
Diffstat (limited to 'test/008-exceptions/src/Main.java')
| -rw-r--r-- | test/008-exceptions/src/Main.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/008-exceptions/src/Main.java b/test/008-exceptions/src/Main.java index 1f76f12460..7f6d0c5956 100644 --- a/test/008-exceptions/src/Main.java +++ b/test/008-exceptions/src/Main.java @@ -14,6 +14,24 @@ * limitations under the License. */ +// An exception that doesn't have a <init>(String) method. +class BadError extends Error { + public BadError() { + super("This is bad by convention"); + } +} + +// A class that throws BadException during static initialization. +class BadInit { + static int dummy; + static { + System.out.println("Static Init"); + if (true) { + throw new BadError(); + } + } +} + /** * Exceptions across method calls */ @@ -29,6 +47,7 @@ public class Main { } public static void main (String args[]) { exceptions_007(); + exceptionsRethrowClassInitFailure(); } private static void catchAndRethrow() { @@ -45,4 +64,26 @@ public class Main { private static void throwNullPointerException() { throw new NullPointerException("first throw"); } + + private static void exceptionsRethrowClassInitFailure() { + try { + try { + BadInit.dummy = 1; + throw new IllegalStateException("Should not reach here."); + } catch (BadError e) { + System.out.println(e); + } + + // Check if it works a second time. + + try { + BadInit.dummy = 1; + throw new IllegalStateException("Should not reach here."); + } catch (BadError e) { + System.out.println(e); + } + } catch (Exception error) { + error.printStackTrace(); + } + } } |