Skip to content

Commit 10d4b1b

Browse files
cpovirkGoogle Java Core Libraries
authored andcommitted
Inline a method that mainly serves to confuse the compiler's reachabililty checking.
It's possible that my motivation for the method was: - to make it more difficult to accidentally operate on `e` intead of `e.getCause()` (as in #7434): If so, I hope that I've addressed that sufficiently by renaming `e` to "`wrapper`". - to share code with [`wrapAndThrowRuntimeExecutionExceptionOrError` in `SimpleTimeLimiter`](https://github.com/google/guava/blob/5338f7c997dac25879378c9aebb692dc6f6cf9da/guava/src/com/google/common/util/concurrent/SimpleTimeLimiter.java#L278C16-L278C60): I mean, I guess we _could_, but meh, especially since the `Futures` copy of the logic benefits from an implementation comment that wouldn't make sense in the `SimpleTimeLimiter` case. RELNOTES=n/a PiperOrigin-RevId: 686551569
1 parent 503c9eb commit 10d4b1b

File tree

2 files changed

+20
-30
lines changed

2 files changed

+20
-30
lines changed

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,22 +1290,17 @@ public String toString() {
12901290
checkNotNull(future);
12911291
try {
12921292
return getUninterruptibly(future);
1293-
} catch (ExecutionException e) {
1294-
wrapAndThrowUnchecked(e.getCause());
1295-
throw new AssertionError();
1296-
}
1297-
}
1298-
1299-
private static void wrapAndThrowUnchecked(Throwable cause) {
1300-
if (cause instanceof Error) {
1301-
throw new ExecutionError((Error) cause);
1293+
} catch (ExecutionException wrapper) {
1294+
if (wrapper.getCause() instanceof Error) {
1295+
throw new ExecutionError((Error) wrapper.getCause());
1296+
}
1297+
/*
1298+
* It's an Exception. (Or it's a non-Error, non-Exception Throwable. From my survey of such
1299+
* classes, I believe that most users intended to extend Exception, so we'll treat it like an
1300+
* Exception.)
1301+
*/
1302+
throw new UncheckedExecutionException(wrapper.getCause());
13021303
}
1303-
/*
1304-
* It's an Exception. (Or it's a non-Error, non-Exception Throwable. From my survey of such
1305-
* classes, I believe that most users intended to extend Exception, so we'll treat it like an
1306-
* Exception.)
1307-
*/
1308-
throw new UncheckedExecutionException(cause);
13091304
}
13101305

13111306
/*

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

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,22 +1377,17 @@ public String toString() {
13771377
checkNotNull(future);
13781378
try {
13791379
return getUninterruptibly(future);
1380-
} catch (ExecutionException e) {
1381-
wrapAndThrowUnchecked(e.getCause());
1382-
throw new AssertionError();
1383-
}
1384-
}
1385-
1386-
private static void wrapAndThrowUnchecked(Throwable cause) {
1387-
if (cause instanceof Error) {
1388-
throw new ExecutionError((Error) cause);
1380+
} catch (ExecutionException wrapper) {
1381+
if (wrapper.getCause() instanceof Error) {
1382+
throw new ExecutionError((Error) wrapper.getCause());
1383+
}
1384+
/*
1385+
* It's an Exception. (Or it's a non-Error, non-Exception Throwable. From my survey of such
1386+
* classes, I believe that most users intended to extend Exception, so we'll treat it like an
1387+
* Exception.)
1388+
*/
1389+
throw new UncheckedExecutionException(wrapper.getCause());
13891390
}
1390-
/*
1391-
* It's an Exception. (Or it's a non-Error, non-Exception Throwable. From my survey of such
1392-
* classes, I believe that most users intended to extend Exception, so we'll treat it like an
1393-
* Exception.)
1394-
*/
1395-
throw new UncheckedExecutionException(cause);
13961391
}
13971392

13981393
/*

0 commit comments

Comments
 (0)