Merge pull request #288 from dicej/eiie-errors

only wrap Exceptions in ExceptionInInitializerErrors, not Errors
This commit is contained in:
Joshua Warner 2014-07-10 14:01:05 -06:00
commit d4d232db89
2 changed files with 42 additions and 1 deletions

View File

@ -4660,7 +4660,8 @@ postInitClass(Thread* t, object c)
PROTECT(t, c); PROTECT(t, c);
ACQUIRE(t, t->m->classLock); 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) |= NeedInitFlag | InitErrorFlag;
classVmFlags(t, c) &= ~InitFlag; classVmFlags(t, c) &= ~InitFlag;

View File

@ -1,4 +1,19 @@
public class Exceptions { 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() { private static void evenMoreDangerous() {
throw new RuntimeException("chaos! panic! overwhelming anxiety!"); throw new RuntimeException("chaos! panic! overwhelming anxiety!");
@ -12,12 +27,37 @@ public class Exceptions {
moreDangerous(); moreDangerous();
} }
private static void expect(boolean v) {
if (! v) throw new RuntimeException();
}
public static void main(String[] args) { public static void main(String[] args) {
boolean threw = false;
try { try {
dangerous(); dangerous();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); 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);
} }
} }