8209771: jdk.test.lib.Utils::runAndCheckException error
authorweijun
Wed, 22 Aug 2018 11:10:45 +0800
changeset 51478 36c72eb60d5b
parent 51477 e77d7687c831
child 51479 0e4d87cf6caf
8209771: jdk.test.lib.Utils::runAndCheckException error Reviewed-by: dholmes
test/lib/jdk/test/lib/Utils.java
--- a/test/lib/jdk/test/lib/Utils.java	Fri Aug 17 13:53:53 2018 -0700
+++ b/test/lib/jdk/test/lib/Utils.java	Wed Aug 22 11:10:45 2018 +0800
@@ -612,7 +612,7 @@
      * @param runnable what we run
      * @param expectedException expected exception
      */
-    public static void runAndCheckException(Runnable runnable, Class<? extends Throwable> expectedException) {
+    public static void runAndCheckException(ThrowingRunnable runnable, Class<? extends Throwable> expectedException) {
         runAndCheckException(runnable, t -> {
             if (t == null) {
                 if (expectedException != null) {
@@ -635,13 +635,14 @@
      * @param runnable what we run
      * @param checkException a consumer which checks that we got expected exception and raises a new exception otherwise
      */
-    public static void runAndCheckException(Runnable runnable, Consumer<Throwable> checkException) {
+    public static void runAndCheckException(ThrowingRunnable runnable, Consumer<Throwable> checkException) {
+        Throwable throwable = null;
         try {
             runnable.run();
-            checkException.accept(null);
         } catch (Throwable t) {
-            checkException.accept(t);
+            throwable = t;
         }
+        checkException.accept(throwable);
     }
 
     /**