Skip to content

Commit

Permalink
Refactor getDoneValue(Object obj) to improve readability of `Cancel…
Browse files Browse the repository at this point in the history
…lation` and `Failure` case handling logic.

RELNOTES=n/a
PiperOrigin-RevId: 683695919
  • Loading branch information
java-team-github-bot authored and Google Java Core Libraries committed Oct 8, 2024
1 parent 4d7c71e commit 01e6a55
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,13 @@ private V getDoneValue(Object obj) throws ExecutionException {
// While this seems like it might be too branch-y, simple benchmarking proves it to be
// unmeasurable (comparing done AbstractFutures with immediateFuture)
if (obj instanceof Cancellation) {
throw cancellationExceptionWithCause("Task was cancelled.", ((Cancellation) obj).cause);
Cancellation cancellation = (Cancellation) obj;
Throwable cause = cancellation.cause;
throw cancellationExceptionWithCause("Task was cancelled.", cause);
} else if (obj instanceof Failure) {
throw new ExecutionException(((Failure) obj).exception);
Failure failure = (Failure) obj;
Throwable exception = failure.exception;
throw new ExecutionException(exception);
} else if (obj == NULL) {
/*
* It's safe to return null because we would only have stored it in the first place if it were
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,13 @@ private V getDoneValue(Object obj) throws ExecutionException {
// While this seems like it might be too branch-y, simple benchmarking proves it to be
// unmeasurable (comparing done AbstractFutures with immediateFuture)
if (obj instanceof Cancellation) {
throw cancellationExceptionWithCause("Task was cancelled.", ((Cancellation) obj).cause);
Cancellation cancellation = (Cancellation) obj;
Throwable cause = cancellation.cause;
throw cancellationExceptionWithCause("Task was cancelled.", cause);
} else if (obj instanceof Failure) {
throw new ExecutionException(((Failure) obj).exception);
Failure failure = (Failure) obj;
Throwable exception = failure.exception;
throw new ExecutionException(exception);
} else if (obj == NULL) {
/*
* It's safe to return null because we would only have stored it in the first place if it were
Expand Down

0 comments on commit 01e6a55

Please sign in to comment.