Skip to content

Commit bc2a256

Browse files
author
Vincent Potucek
committed
try can use automatic resource management
1 parent aea22b9 commit bc2a256

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

impl/maven-executor/src/main/java/org/apache/maven/cling/executor/forked/ForkedMavenExecutor.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,10 @@ protected CountDownLatch pump(Process p, ExecutorRequest executorRequest) {
163163
CountDownLatch latch = new CountDownLatch(3);
164164
String suffix = "-pump-" + p.pid();
165165
Thread stdoutPump = new Thread(() -> {
166-
try (OutputStream stdout = executorRequest.stdOut().orElse(OutputStream.nullOutputStream())) {
166+
try {
167+
OutputStream stdout = executorRequest.stdOut().orElse(OutputStream.nullOutputStream());
167168
p.getInputStream().transferTo(stdout);
169+
stdout.flush();
168170
} catch (IOException e) {
169171
throw new UncheckedIOException(e);
170172
} finally {
@@ -174,8 +176,10 @@ protected CountDownLatch pump(Process p, ExecutorRequest executorRequest) {
174176
stdoutPump.setName("stdout" + suffix);
175177
stdoutPump.start();
176178
Thread stderrPump = new Thread(() -> {
177-
try (OutputStream stderr = executorRequest.stdErr().orElse(OutputStream.nullOutputStream())) {
179+
try {
180+
OutputStream stderr = executorRequest.stdErr().orElse(OutputStream.nullOutputStream());
178181
p.getErrorStream().transferTo(stderr);
182+
stderr.flush();
179183
} catch (IOException e) {
180184
throw new UncheckedIOException(e);
181185
} finally {
@@ -185,8 +189,10 @@ protected CountDownLatch pump(Process p, ExecutorRequest executorRequest) {
185189
stderrPump.setName("stderr" + suffix);
186190
stderrPump.start();
187191
Thread stdinPump = new Thread(() -> {
188-
try (OutputStream in = p.getOutputStream()) {
192+
try {
193+
OutputStream in = p.getOutputStream();
189194
executorRequest.stdIn().orElse(InputStream.nullInputStream()).transferTo(in);
195+
in.flush();
190196
} catch (IOException e) {
191197
throw new UncheckedIOException(e);
192198
} finally {

0 commit comments

Comments
 (0)