8086208: java/lang/ProcessHandle/OnExitTest.java: IllegalThreadStateException: process hasn't exited
Reviewed-by: martin, dholmes
--- 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
*/