-
Bug
-
Resolution: Fixed
-
P2
-
1.4.0
-
None
-
beta
-
generic
-
generic
Peter.Jones@East pointed out that only Errors should be allowed to propagate out
of reflective invocations; arbitrary Throwables should be wrapped in
InvocationTargetException. This is a change in behavior due to the reflection
rewrite that was put back in build 51; see also bug 4417941, which is related.
Test case from above author:
import java.lang.reflect.*;
public class TestThrowable {
public static void main(String[] args) {
try {
Class c = TestThrowable.class;
Method tt = c.getDeclaredMethod("throwThrowable", null);
Method te = c.getDeclaredMethod("throwError", null);
try {
System.out.println("invoking throwThrowable():");
tt.invoke(null, null);
} catch (InvocationTargetException e) {
System.out.println(
"--> caught InvocationTargetException containing: " +
e.getTargetException());
} catch (Throwable t) {
System.out.println("--> caught Throwable directly: " + t);
}
try {
System.out.println("invoking throwError():");
te.invoke(null, null);
} catch (InvocationTargetException e) {
System.out.println(
"--> caught InvocationTargetException containing: " +
e.getTargetException());
} catch (Throwable t) {
System.out.println("--> caught Throwable directly: " + t);
}
} catch (Exception e) {
System.err.println("--> unexpected exception:");
e.printStackTrace();
}
}
static void throwThrowable() throws Throwable {
throw new Throwable();
}
static void throwError() {
throw new Error();
}
}
of reflective invocations; arbitrary Throwables should be wrapped in
InvocationTargetException. This is a change in behavior due to the reflection
rewrite that was put back in build 51; see also bug 4417941, which is related.
Test case from above author:
import java.lang.reflect.*;
public class TestThrowable {
public static void main(String[] args) {
try {
Class c = TestThrowable.class;
Method tt = c.getDeclaredMethod("throwThrowable", null);
Method te = c.getDeclaredMethod("throwError", null);
try {
System.out.println("invoking throwThrowable():");
tt.invoke(null, null);
} catch (InvocationTargetException e) {
System.out.println(
"--> caught InvocationTargetException containing: " +
e.getTargetException());
} catch (Throwable t) {
System.out.println("--> caught Throwable directly: " + t);
}
try {
System.out.println("invoking throwError():");
te.invoke(null, null);
} catch (InvocationTargetException e) {
System.out.println(
"--> caught InvocationTargetException containing: " +
e.getTargetException());
} catch (Throwable t) {
System.out.println("--> caught Throwable directly: " + t);
}
} catch (Exception e) {
System.err.println("--> unexpected exception:");
e.printStackTrace();
}
}
static void throwThrowable() throws Throwable {
throw new Throwable();
}
static void throwError() {
throw new Error();
}
}