Skip to content

Commit 62ff686

Browse files
authored
Merge pull request #445 from dmlloyd/process
Avoid NPE when error is redirected to output
2 parents c48273b + dbe36c1 commit 62ff686

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

process/src/main/java/io/smallrye/common/process/PipelineRunner.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ int createInputThread(ThreadFactory tf, ProcessRunner<?> runner) throws IOExcept
114114
int createErrorThreads(ThreadFactory tf, ProcessRunner<?> runner) throws IOException {
115115
int strategy = processBuilder.errorStrategy;
116116
if (strategy == ERR_REDIRECT) {
117+
processBuilder.errorGatherOnFail = false;
118+
processBuilder.errorLogOnSuccess = false;
117119
pb.redirectErrorStream(true);
118120
return 0;
119121
}

process/src/main/java/io/smallrye/common/process/ProcessRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ private void initialize(final ThreadFactory tf) {
104104
throw new PipelineExecutionException("Failed to create process thread(s)", e);
105105
}
106106
try {
107+
taskCount = taskCnt;
107108
startThreads();
108109
} catch (Throwable t) {
109110
status = STATUS_FAILED;
@@ -120,7 +121,6 @@ private void initialize(final ThreadFactory tf) {
120121
processes.forEach(ProcessUtil::destroyAllForcibly);
121122
throw t;
122123
}
123-
taskCount = taskCnt;
124124
} catch (Throwable t) {
125125
status = STATUS_FAILED;
126126
unpark();

process/src/test/java/io/smallrye/common/process/TestBasicExecution.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.smallrye.common.process;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
45
import static org.junit.jupiter.api.Assertions.assertTrue;
56
import static org.junit.jupiter.api.Assertions.fail;
67

@@ -232,6 +233,17 @@ public void testWorkingDirectory() throws Exception {
232233
.run());
233234
}
234235

236+
@Test
237+
public void testNullPointerOnRedirect() throws Exception {
238+
assertThrows(AbnormalExitException.class, () -> {
239+
ProcessBuilder.newBuilder(ProcessUtil.pathOfJava())
240+
.arguments(findHelper(ErrorifierWithOutput.class, "1"))
241+
.output().gatherOnFail(true).inherited()
242+
.error().gatherOnFail(true).redirect()
243+
.run();
244+
});
245+
}
246+
235247
@Test
236248
public void testFormatInfiniteLoop() {
237249
// just make sure it doesn't infinitely loop

0 commit comments

Comments
 (0)