Skip to content

Commit 199f099

Browse files
committed
Fix duration conversion error
Fixes #478
1 parent 3af34aa commit 199f099

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.lang.invoke.ConstantBootstraps;
2727
import java.lang.invoke.MethodHandles;
2828
import java.lang.invoke.VarHandle;
29-
import java.time.temporal.ChronoUnit;
3029
import java.util.ArrayList;
3130
import java.util.List;
3231
import java.util.concurrent.CopyOnWriteArrayList;
@@ -422,7 +421,7 @@ int createWaitForThread(ThreadFactory tf, ProcessRunner<?> runner) throws IOExce
422421
awaitIoDone();
423422
if (process.isAlive() && processBuilder.softExitTimeout != null) {
424423
// start the countdown!
425-
if (ProcessUtil.stillRunningAfter(process, processBuilder.softExitTimeout.get(ChronoUnit.NANOS))) {
424+
if (ProcessUtil.stillRunningAfter(process, processBuilder.softExitTimeout)) {
426425
ste = true;
427426
if (process.supportsNormalTermination()) {
428427
// start knocking on the door
@@ -431,7 +430,7 @@ int createWaitForThread(ThreadFactory tf, ProcessRunner<?> runner) throws IOExce
431430
}
432431
}
433432
if (process.isAlive() && processBuilder.hardExitTimeout != null) {
434-
if (ProcessUtil.stillRunningAfter(process, processBuilder.hardExitTimeout.get(ChronoUnit.NANOS))) {
433+
if (ProcessUtil.stillRunningAfter(process, processBuilder.hardExitTimeout)) {
435434
hte = true;
436435
// obliterate
437436
ProcessUtil.destroyAllForcibly(process.toHandle());

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.nio.charset.UnsupportedCharsetException;
66
import java.nio.file.Files;
77
import java.nio.file.Path;
8+
import java.time.Duration;
89
import java.util.List;
910
import java.util.Optional;
1011
import java.util.concurrent.ExecutionException;
@@ -138,6 +139,8 @@ public static String nameOfJava() {
138139
return JavaPath.javaName;
139140
}
140141

142+
private static final Duration LONGEST_NS = Duration.ofNanos(Long.MAX_VALUE);
143+
141144
/**
142145
* Wait (uninterruptibly) for some amount of time for the given process to finish.
143146
*
@@ -146,6 +149,18 @@ public static String nameOfJava() {
146149
* @return {@code true} if the process is still running after the elapsed time, or {@code false} if it has exited
147150
*/
148151
public static boolean stillRunningAfter(Process proc, long nanos) {
152+
return stillRunningAfter(proc, Duration.ofNanos(nanos));
153+
}
154+
155+
/**
156+
* Wait (uninterruptibly) for some amount of time for the given process to finish.
157+
*
158+
* @param proc the process (must not be {@code null})
159+
* @param time the amount of time to wait (must not be {@code null})
160+
* @return {@code true} if the process is still running after the elapsed time, or {@code false} if it has exited
161+
*/
162+
public static boolean stillRunningAfter(Process proc, Duration time) {
163+
long nanos = time.compareTo(LONGEST_NS) > 0 ? Long.MAX_VALUE : time.toNanos();
149164
boolean intr = false;
150165
try {
151166
long start = System.nanoTime();

0 commit comments

Comments
 (0)