This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-exec.git

commit f59fd40352a27a1a9cc2d6e28fd518a284a3c9e3
Author: Gary Gregory <[email protected]>
AuthorDate: Sun Dec 31 15:48:19 2023 -0500

    Fix file resource leak in test
---
 .../java/org/apache/commons/exec/issues/Exec62Test.java     | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/test/java/org/apache/commons/exec/issues/Exec62Test.java 
b/src/test/java/org/apache/commons/exec/issues/Exec62Test.java
index b21cdd30..db1520ec 100644
--- a/src/test/java/org/apache/commons/exec/issues/Exec62Test.java
+++ b/src/test/java/org/apache/commons/exec/issues/Exec62Test.java
@@ -53,13 +53,14 @@ public class Exec62Test {
         executor.setExitValues(null); // ignore exit values
         executor.setWatchdog(watchdog);
 
-        final OutputStream fos = Files.newOutputStream(outputFile);
-        final PumpStreamHandler streamHandler = new PumpStreamHandler(fos);
-        executor.setStreamHandler(streamHandler);
-        executor.execute(commandLine);
+        try (OutputStream fos = Files.newOutputStream(outputFile)) {
+            final PumpStreamHandler streamHandler = new PumpStreamHandler(fos);
+            executor.setStreamHandler(streamHandler);
+            executor.execute(commandLine);
 
-        if (watchdog.killedProcess()) {
-            throw new TimeoutException(String.format("Transcode process was 
killed on timeout %1$s ms, command line %2$s", 4000, commandLine.toString()));
+            if (watchdog.killedProcess()) {
+                throw new TimeoutException(String.format("Transcode process 
was killed on timeout %1$s ms, command line %2$s", 4000, 
commandLine.toString()));
+            }
         }
     }
 

Reply via email to