8137020: [TESTBUG] Utils.runAndCheckException doesn't work well if no exception thrown
authorkzhaldyb
Thu, 24 Sep 2015 18:24:10 +0300
changeset 33080 73c9bbe40ff8
parent 33079 65fc34b22fdb
child 33081 71794b149055
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
hotspot/test/testlibrary/jdk/test/lib/Utils.java
--- 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());
+        }
     }
 
 }
+