You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "elharo (via GitHub)" <gi...@apache.org> on 2026/07/01 13:38:00 UTC

[PR] CommandLineUtils: ensure all pumpers are waited on in try-finally [maven-shared-utils]

elharo opened a new pull request, #399:
URL: https://github.com/apache/maven-shared-utils/pull/399

   In `CommandLineUtils.call()`, `waitUntilDone()` was called on `inputFeeder`, `outputPumper`, and `errorPumper` sequentially without try-finally (lines 298-303 of the original). If an earlier call threw (e.g., `InterruptedException`), the remaining pumpers were never waited on, leaving their threads potentially running.
   
   The commented-out code just above (lines 277-297) shows the original author intended a try-finally chain but never enabled it.
   
   **Fix:** Replaced the sequential calls and the dead commented block with a proper try-finally chain ensuring all three pumpers are waited on regardless of exceptions from earlier ones.
   
   Fixes https://github.com/apache/maven-shared-utils/issues/398


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CommandLineUtils: ensure all pumpers are waited on in try-finally [maven-shared-utils]

Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo merged PR #399:
URL: https://github.com/apache/maven-shared-utils/pull/399


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CommandLineUtils: ensure all pumpers are waited on in try-finally [maven-shared-utils]

Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo commented on code in PR #399:
URL: https://github.com/apache/maven-shared-utils/pull/399#discussion_r3703185333


##########
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();
+                        }

Review Comment:
   Makes sense, but I think I;m going to leave that for a future PR



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CommandLineUtils: ensure all pumpers are waited on in try-finally [maven-shared-utils]

Posted by "desruisseaux (via GitHub)" <gi...@apache.org>.
desruisseaux commented on code in PR #399:
URL: https://github.com/apache/maven-shared-utils/pull/399#discussion_r3702644423


##########
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();
+                        }

Review Comment:
   It works, but if more than one exception is thrown, we see only the last one. It would be possible to keep all of them with `catch (Throwable e)` and `Throwable.addSuppressed(e)` calls, but that would make the code more complex (I'm not sure it would be worth). Alternatively, this exception handling could be made easier if the pumpers implement `AutoCloseable`.
   
   I'm not really suggesting a change. I'm not against deciding that it is not worth to keep all exceptions. Just submitting for your consideration and letting you decide.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org