From 9fe24089bf8d91ac6b1e048bd30c2162c5877390 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Wed, 1 Jul 2026 09:37:42 -0400 Subject: [PATCH] CommandLineUtils: ensure all pumpers are waited on in try-finally --- .../shared/utils/cli/CommandLineUtils.java | 36 ++++++------------- 1 file changed, 10 insertions(+), 26 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 5c0307c5..ee676901 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 @@ -274,34 +274,18 @@ public Integer call() throws CommandLineException { 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(); - // } - // } - if (inputFeeder != null) { - inputFeeder.waitUntilDone(); + try { + if (inputFeeder != null) { + inputFeeder.waitUntilDone(); + } + } finally { + try { + outputPumper.waitUntilDone(); + } finally { + errorPumper.waitUntilDone(); + } } - outputPumper.waitUntilDone(); - errorPumper.waitUntilDone(); - if (inputFeeder != null && inputFeeder.getException() != null) { throw new CommandLineException("Failure processing stdin.", inputFeeder.getException()); }