changeset 52204:36c72eb60d5b

8209771: jdk.test.lib.Utils::runAndCheckException error Reviewed-by: dholmes
author weijun
date Wed, 22 Aug 2018 11:10:45 +0800
parents e77d7687c831
children 0e4d87cf6caf
files test/lib/jdk/test/lib/Utils.java
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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);
     }
 
     /**