MCPcopy Create free account
hub / github.com/antlr/codebuff / FuturesGetChecked

Class FuturesGetChecked

output/java_guava/1.4.16/FuturesGetChecked.java:45–310  ·  view source on GitHub ↗

Static methods used to implement Futures#getChecked(Future, Class).

Source from the content-addressed store, hash-verified

43
44
45@GwtIncompatible
46final class FuturesGetChecked {
47 @CanIgnoreReturnValue
48 static <V, X extends Exception> V getChecked(Future<V> future, Class<X> exceptionClass)
49 throws X {
50 return getChecked(bestGetCheckedTypeValidator(), future, exceptionClass);
51 }
52
53 /**
54 * Implementation of {@link Futures#getChecked(Future, Class)}.
55 */
56
57 @CanIgnoreReturnValue
58 @VisibleForTesting
59 static <V, X extends Exception> V getChecked(GetCheckedTypeValidator validator, Future<V> future, Class<X> exceptionClass)
60 throws X {
61 validator.validateClass(exceptionClass);
62 try {
63 return future.get();
64 } catch (InterruptedException e) {
65 currentThread().interrupt();
66 throw newWithCause(exceptionClass, e);
67 } catch (ExecutionException e) {
68 wrapAndThrowExceptionOrError(e.getCause(), exceptionClass);
69 throw new AssertionError();
70 }
71 }
72
73 /**
74 * Implementation of {@link Futures#getChecked(Future, Class, long, TimeUnit)}.
75 */
76
77 @CanIgnoreReturnValue
78 static <V, X extends Exception> V getChecked(Future<V> future, Class<X> exceptionClass, long timeout, TimeUnit unit)
79 throws X {
80 // TODO(cpovirk): benchmark a version of this method that accepts a GetCheckedTypeValidator
81 bestGetCheckedTypeValidator().validateClass(exceptionClass);
82 try {
83 return future.get(timeout, unit);
84 } catch (InterruptedException e) {
85 currentThread().interrupt();
86 throw newWithCause(exceptionClass, e);
87 } catch (TimeoutException e) {
88 throw newWithCause(exceptionClass, e);
89 } catch (ExecutionException e) {
90 wrapAndThrowExceptionOrError(e.getCause(), exceptionClass);
91 throw new AssertionError();
92 }
93 }
94
95 @VisibleForTesting
96 interface GetCheckedTypeValidator {
97
98 void validateClass(Class<? extends Exception> exceptionClass);
99 }
100
101 private static GetCheckedTypeValidator bestGetCheckedTypeValidator() {
102 return GetCheckedTypeValidatorHolder.BEST_VALIDATOR;

Callers

nothing calls this directly

Calls 3

naturalMethod · 0.95
reverseMethod · 0.45
onResultOfMethod · 0.45

Tested by

no test coverage detected