8137020: [TESTBUG] Utils.runAndCheckException doesn't work well if no exception thrown
Summary: Changed handling a case when expected exception wasn't thrown
Reviewed-by: iignatyev
--- a/hotspot/test/testlibrary/jdk/test/lib/Utils.java Wed Sep 16 13:50:57 2015 +0000
+++ b/hotspot/test/testlibrary/jdk/test/lib/Utils.java Thu Sep 24 18:24:10 2015 +0300
@@ -441,10 +441,11 @@
* @param expectedException expected exception
*/
public static void runAndCheckException(Runnable runnable, Class<? extends Throwable> expectedException) {
+ boolean expectedExceptionWasNotThrown = false;
try {
runnable.run();
if (expectedException != null) {
- throw new AssertionError("Didn't get expected exception " + expectedException.getSimpleName());
+ expectedExceptionWasNotThrown = true;
}
} catch (Throwable t) {
if (expectedException == null) {
@@ -455,6 +456,10 @@
t.getClass().getSimpleName(), expectedException.getSimpleName()), t);
}
}
+ if (expectedExceptionWasNotThrown) {
+ throw new AssertionError("Didn't get expected exception " + expectedException.getSimpleName());
+ }
}
}
+