8086208: java/lang/ProcessHandle/OnExitTest.java: IllegalThreadStateException: process hasn't exited
authorrriggs
Wed, 17 Jun 2015 16:03:49 -0400
changeset 31182 07956922e5d8
parent 31181 27ccb72932ee
child 31183 eb0ffbecb4ba
8086208: java/lang/ProcessHandle/OnExitTest.java: IllegalThreadStateException: process hasn't exited Reviewed-by: martin, dholmes
jdk/src/java.base/unix/classes/java/lang/ProcessImpl.java
jdk/test/java/lang/ProcessHandle/OnExitTest.java
--- a/jdk/src/java.base/unix/classes/java/lang/ProcessImpl.java	Wed Jun 17 15:48:28 2015 -0400
+++ b/jdk/src/java.base/unix/classes/java/lang/ProcessImpl.java	Wed Jun 17 16:03:49 2015 -0400
@@ -542,7 +542,22 @@
     @Override
     public CompletableFuture<Process> onExit() {
         return ProcessHandleImpl.completion(pid, false)
-                .handleAsync((exitStatus, unusedThrowable) -> this);
+                .handleAsync((exitStatus, unusedThrowable) -> {
+                    boolean interrupted = false;
+                    while (true) {
+                        // Ensure that the concurrent task setting the exit status has completed
+                        try {
+                            waitFor();
+                            break;
+                        } catch (InterruptedException ie) {
+                            interrupted = true;
+                        }
+                    }
+                    if (interrupted) {
+                        Thread.currentThread().interrupt();
+                    }
+                    return this;
+                });
     }
 
     @Override
--- a/jdk/test/java/lang/ProcessHandle/OnExitTest.java	Wed Jun 17 15:48:28 2015 -0400
+++ b/jdk/test/java/lang/ProcessHandle/OnExitTest.java	Wed Jun 17 16:03:49 2015 -0400
@@ -26,21 +26,17 @@
 import java.time.Duration;
 import java.time.Instant;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ExecutionException;
-import java.util.stream.Collectors;
-import jdk.testlibrary.Platform;
 import org.testng.annotations.Test;
 import org.testng.Assert;
 import org.testng.TestNG;
 
 /*
  * @test
- * @library /lib/testlibrary
  * @summary Functions of Process.onExit and ProcessHandle.onExit
  * @author Roger Riggs
  */