From 94b82c30654baf0d33ea59369dbd5666a69979d0 Mon Sep 17 00:00:00 2001 From: Moses Nakamura Date: Sun, 14 May 2023 16:33:04 -0400 Subject: [PATCH] fixed for errorprone --- .../exec/CompletableFutureExecuteResultHandler.java | 2 ++ src/main/java/ch/vorburger/exec/ManagedProcess.java | 10 ++++++---- .../java/ch/vorburger/exec/MultiCauseIOException.java | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/ch/vorburger/exec/CompletableFutureExecuteResultHandler.java b/src/main/java/ch/vorburger/exec/CompletableFutureExecuteResultHandler.java index bfc98be..edf16b5 100644 --- a/src/main/java/ch/vorburger/exec/CompletableFutureExecuteResultHandler.java +++ b/src/main/java/ch/vorburger/exec/CompletableFutureExecuteResultHandler.java @@ -36,6 +36,7 @@ public CompletableFutureExecuteResultHandler(CompletableFuture asyncRes * * @param exitValue the exit value of the sub-process */ + @Override public void onProcessComplete(int exitValue) { asyncResult.complete(exitValue); } @@ -45,6 +46,7 @@ public void onProcessComplete(int exitValue) { * * @param e the {@code ExecuteException} containing the root cause */ + @Override public void onProcessFailed(ExecuteException e) { asyncResult.completeExceptionally(e); } diff --git a/src/main/java/ch/vorburger/exec/ManagedProcess.java b/src/main/java/ch/vorburger/exec/ManagedProcess.java index c92eb89..b386c70 100644 --- a/src/main/java/ch/vorburger/exec/ManagedProcess.java +++ b/src/main/java/ch/vorburger/exec/ManagedProcess.java @@ -30,8 +30,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.lang.invoke.MethodHandles; -import java.time.Duration; -import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Optional; @@ -133,7 +131,7 @@ public class ManagedProcess implements ManagedProcessState { this.consoleBufferMaxLines = consoleBufferMaxLines; this.outputStreamLogDispatcher = outputStreamLogDispatcher; this.asyncResult = new CompletableFuture<>(); - this.asyncResult.handle((result, e) -> + var unused = this.asyncResult.handle((result, e) -> { if (e == null) { logger.info(this.getProcLongName() + " just exited, with value " + result); @@ -336,7 +334,7 @@ protected ManagedProcessException handleInterruptedException(InterruptedExceptio protected ManagedProcessException handleException(Exception e) throws ManagedProcessException { // TODO Not sure how to best handle this... opinions welcome (see also below) - final String message = "Huh?! Exception should normally never happen here..." + String message = "Huh?! Exception should normally never happen here..." + getProcLongName(); logger.error(message, e); return new ManagedProcessException(message, e); @@ -348,6 +346,8 @@ protected void checkResult() throws ManagedProcessException { // We already terminated (or never started) try { asyncResult.get(); // just called to throw the exception + } catch (InterruptedException e) { + throw handleInterruptedException(e); } catch (Exception e) { logger.error(getProcLongName() + " failed", e); throw new ManagedProcessException(getProcLongName() + " failed with Exception: " + getLastConsoleLines(), @@ -433,6 +433,8 @@ public void notifyProcessHalted() { public int exitValue() throws ManagedProcessException { try { return asyncResult.get(); + } catch (InterruptedException e) { + throw handleInterruptedException(e); } catch (Exception e) { throw new ManagedProcessException("No Exit Value, but an exception, is available for " + getProcLongName(), e); diff --git a/src/main/java/ch/vorburger/exec/MultiCauseIOException.java b/src/main/java/ch/vorburger/exec/MultiCauseIOException.java index 61c9a3a..cc3e5fb 100644 --- a/src/main/java/ch/vorburger/exec/MultiCauseIOException.java +++ b/src/main/java/ch/vorburger/exec/MultiCauseIOException.java @@ -38,7 +38,7 @@ public class MultiCauseIOException extends IOException { // Doesn't something like this (or helpers for it) exist else? Couldn't find in commons-lang or // Spring... - protected List causes = new ArrayList<>(); + protected ArrayList causes = new ArrayList<>(); /** * Add a Cause. Must be called at least once! (Otherwise why use this.)