8190911: tools/jdeps/MultiReleaseJar.java failed with java.lang.IllegalThreadStateException
authormchung
Mon, 27 Nov 2017 14:41:59 -0800
changeset 47945 39afb6894e3a
parent 47943 cece8b7adf10
child 47946 e5df7ccc4b73
8190911: tools/jdeps/MultiReleaseJar.java failed with java.lang.IllegalThreadStateException Reviewed-by: bpb
test/langtools/tools/jdeps/MultiReleaseJar.java
--- a/test/langtools/tools/jdeps/MultiReleaseJar.java	Mon Nov 27 22:22:03 2017 +0100
+++ b/test/langtools/tools/jdeps/MultiReleaseJar.java	Mon Nov 27 14:41:59 2017 -0800
@@ -240,17 +240,26 @@
         cmds[0] = cmdPath.resolve(cmds[0]).toString();
         ProcessBuilder pb = new ProcessBuilder(cmds);
         pb.directory(mrjar.toFile());
-        Process p = pb.start();
-        p.waitFor(10, TimeUnit.SECONDS);
-        String out;
-        try (InputStream is = p.getInputStream()) {
-            out = new String(is.readAllBytes());
+        Process p = null;
+        try {
+            p = pb.start();
+            p.waitFor();
+
+            String out;
+            try (InputStream is = p.getInputStream()) {
+                out = new String(is.readAllBytes());
+            }
+            String err;
+            try (InputStream is = p.getErrorStream()) {
+                err = new String(is.readAllBytes());
+            }
+            return new Result(cmd, p.exitValue(), out, err);
+        } catch (Throwable t) {
+            if (p != null) {
+                p.destroyForcibly().waitFor();
+            }
+            throw t;
         }
-        String err;
-        try (InputStream is = p.getErrorStream()) {
-            err = new String(is.readAllBytes());
-        }
-        return new Result(cmd, p.exitValue(), out, err);
     }
 
     void checkResult(Result r) throws Exception {