This is an automated email from the ASF dual-hosted git repository. elharo pushed a commit to branch fix/process-streams-close in repository https://gitbox.apache.org/repos/asf/maven-shared-utils.git
commit 8cbf8ecc07c1739a7f1d27c7a36517c1397b3cc6 Author: Elliotte Rusty Harold <[email protected]> AuthorDate: Wed Jul 1 10:42:05 2026 -0400 Close process streams after exit to work around JDK-4311711 hang --- .../maven/shared/utils/cli/CommandLineUtils.java | 42 +++++++++++----------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/apache/maven/shared/utils/cli/CommandLineUtils.java b/src/main/java/org/apache/maven/shared/utils/cli/CommandLineUtils.java index 5c0307c..33a183d 100644 --- a/src/main/java/org/apache/maven/shared/utils/cli/CommandLineUtils.java +++ b/src/main/java/org/apache/maven/shared/utils/cli/CommandLineUtils.java @@ -18,6 +18,7 @@ */ package org.apache.maven.shared.utils.cli; +import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import java.util.ArrayList; @@ -274,27 +275,26 @@ public abstract class CommandLineUtils { int returnValue = p.waitFor(); - // TODO Find out if waitUntilDone needs to be called using a try-finally construct. The method may - // throw an - // InterruptedException so that calls to waitUntilDone may be skipped. - // try - // { - // if ( inputFeeder != null ) - // { - // inputFeeder.waitUntilDone(); - // } - // } - // finally - // { - // try - // { - // outputPumper.waitUntilDone(); - // } - // finally - // { - // errorPumper.waitUntilDone(); - // } - // } + // Close the process streams to work around JDK-4311711: + // Process.getInputStream().read() can hang indefinitely + // even after the process has terminated. Closing the + // streams causes the pumpers' readLine() calls to return. + try { + p.getOutputStream().close(); + } catch (IOException e) { + // ignore + } + try { + p.getInputStream().close(); + } catch (IOException e) { + // ignore + } + try { + p.getErrorStream().close(); + } catch (IOException e) { + // ignore + } + if (inputFeeder != null) { inputFeeder.waitUntilDone(); }
