Skip to content

Commit

Permalink
fixed for errorprone
Browse files Browse the repository at this point in the history
  • Loading branch information
mosesn committed May 14, 2023
1 parent e822372 commit 30e05e0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public CompletableFutureExecuteResultHandler(CompletableFuture<Integer> asyncRes
*
* @param exitValue the exit value of the sub-process
*/
@Override
public void onProcessComplete(int exitValue) {
asyncResult.complete(exitValue);
}
Expand All @@ -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);
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/ch/vorburger/exec/ManagedProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -133,7 +131,7 @@ public class ManagedProcess implements ManagedProcessState {
this.consoleBufferMaxLines = consoleBufferMaxLines;
this.outputStreamLogDispatcher = outputStreamLogDispatcher;
this.asyncResult = new CompletableFuture<>();
this.asyncResult.<Void>handle((result, e) ->
var unused = this.asyncResult.<Void>handle((result, e) ->
{
if (e == null) {
logger.info(this.getProcLongName() + " just exited, with value " + result);
Expand Down Expand Up @@ -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);
Expand All @@ -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(),
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 30e05e0

Please sign in to comment.