Skip to content

Commit 01e6a55

Browse files
java-team-github-botGoogle Java Core Libraries
authored andcommitted
Refactor getDoneValue(Object obj) to improve readability of Cancellation and Failure case handling logic.
RELNOTES=n/a PiperOrigin-RevId: 683695919
1 parent 4d7c71e commit 01e6a55

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

android/guava/src/com/google/common/util/concurrent/AbstractFuture.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,13 @@ private V getDoneValue(Object obj) throws ExecutionException {
592592
// While this seems like it might be too branch-y, simple benchmarking proves it to be
593593
// unmeasurable (comparing done AbstractFutures with immediateFuture)
594594
if (obj instanceof Cancellation) {
595-
throw cancellationExceptionWithCause("Task was cancelled.", ((Cancellation) obj).cause);
595+
Cancellation cancellation = (Cancellation) obj;
596+
Throwable cause = cancellation.cause;
597+
throw cancellationExceptionWithCause("Task was cancelled.", cause);
596598
} else if (obj instanceof Failure) {
597-
throw new ExecutionException(((Failure) obj).exception);
599+
Failure failure = (Failure) obj;
600+
Throwable exception = failure.exception;
601+
throw new ExecutionException(exception);
598602
} else if (obj == NULL) {
599603
/*
600604
* It's safe to return null because we would only have stored it in the first place if it were

guava/src/com/google/common/util/concurrent/AbstractFuture.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,13 @@ private V getDoneValue(Object obj) throws ExecutionException {
592592
// While this seems like it might be too branch-y, simple benchmarking proves it to be
593593
// unmeasurable (comparing done AbstractFutures with immediateFuture)
594594
if (obj instanceof Cancellation) {
595-
throw cancellationExceptionWithCause("Task was cancelled.", ((Cancellation) obj).cause);
595+
Cancellation cancellation = (Cancellation) obj;
596+
Throwable cause = cancellation.cause;
597+
throw cancellationExceptionWithCause("Task was cancelled.", cause);
596598
} else if (obj instanceof Failure) {
597-
throw new ExecutionException(((Failure) obj).exception);
599+
Failure failure = (Failure) obj;
600+
Throwable exception = failure.exception;
601+
throw new ExecutionException(exception);
598602
} else if (obj == NULL) {
599603
/*
600604
* It's safe to return null because we would only have stored it in the first place if it were

0 commit comments

Comments
 (0)