changeset 12213:203d0c15a4fb

8086208: java/lang/ProcessHandle/OnExitTest.java: IllegalThreadStateException: process hasn't exited Reviewed-by: martin, dholmes
author rriggs
date Wed, 17 Jun 2015 16:03:49 -0400
parents 2ebd2395e3e8
children 643306cf8ecf
files src/java.base/unix/classes/java/lang/ProcessImpl.java test/java/lang/ProcessHandle/OnExitTest.java
diffstat 2 files changed, 16 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/unix/classes/java/lang/ProcessImpl.java	Wed Jun 17 15:48:28 2015 -0400
+++ b/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/test/java/lang/ProcessHandle/OnExitTest.java	Wed Jun 17 15:48:28 2015 -0400
+++ b/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
  */