Skip to content

Commit

Permalink
Improve AtomicExecuteResultHandler error message for corner case
Browse files Browse the repository at this point in the history
  • Loading branch information
vorburger committed May 13, 2023
1 parent cc9d4be commit 8bfcb29
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/main/java/ch/vorburger/exec/AtomicExecuteResultHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,20 @@ public String toString() {

@Override
public void onProcessComplete(int exitValue) {
if (!holder.compareAndSet(null, new Holder(exitValue))) {
LOG.error("onProcessComplete({}) will throw IllegalStateException, already set: {}", exitValue, holder);
throw new IllegalStateException("Result already set");
Holder witness = holder.compareAndExchange(null, new Holder(exitValue));
if (witness != null) {
LOG.error("onProcessComplete({}) will throw IllegalStateException, already set: {}", exitValue, witness);
throw new IllegalStateException(
"Ignoring exit value " + exitValue + " because result already set: " + witness);
}
}

@Override
public void onProcessFailed(ExecuteException e) {
if (!holder.compareAndSet(null, new Holder(e))) {
LOG.error("onProcessFailed({}) will throw IllegalStateException, already set: {}", e, holder);
throw new IllegalStateException("Result already set");
Holder witness = holder.compareAndExchange(null, new Holder(e));
if (witness != null) {
LOG.error("onProcessFailed({}) will throw IllegalStateException, already set: {}", e, witness);
throw new IllegalStateException("Ignoring Exception, because result already set: " + witness, e);
}
}

Expand Down

0 comments on commit 8bfcb29

Please sign in to comment.