From 1b83ef7eb32dcad70d5726ccaa0ae689dad3bc61 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 10 Jul 2014 13:27:18 -0600 Subject: [PATCH] only wrap Exceptions in ExceptionInInitializerErrors, not Errors --- src/machine.cpp | 3 ++- test/Exceptions.java | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/machine.cpp b/src/machine.cpp index 33356f3ea5..2f28cbf86f 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -4660,7 +4660,8 @@ postInitClass(Thread* t, object c) PROTECT(t, c); ACQUIRE(t, t->m->classLock); - if (t->exception) { + if (t->exception + and instanceOf(t, type(t, Machine::ExceptionType), t->exception)) { classVmFlags(t, c) |= NeedInitFlag | InitErrorFlag; classVmFlags(t, c) &= ~InitFlag; diff --git a/test/Exceptions.java b/test/Exceptions.java index 5983db1c31..15f1c99c1d 100644 --- a/test/Exceptions.java +++ b/test/Exceptions.java @@ -1,4 +1,19 @@ public class Exceptions { + static class ThrowError { + static { + if (true) throw new AssertionError(); + } + + static void foo() { } + } + + static class ThrowException { + static { + if (true) throw new RuntimeException(); + } + + static void foo() { } + } private static void evenMoreDangerous() { throw new RuntimeException("chaos! panic! overwhelming anxiety!"); @@ -12,12 +27,37 @@ public class Exceptions { moreDangerous(); } + private static void expect(boolean v) { + if (! v) throw new RuntimeException(); + } + public static void main(String[] args) { + boolean threw = false; try { dangerous(); } catch (Exception e) { e.printStackTrace(); + threw = true; } + expect(threw); + threw = false; + + try { + ThrowError.foo(); + } catch (AssertionError e) { + e.printStackTrace(); + threw = true; + } + expect(threw); + threw = false; + + try { + ThrowException.foo(); + } catch (ExceptionInInitializerError e) { + e.printStackTrace(); + threw = true; + } + expect(threw); } }