@Override public V getUnchecked(K key) { try { return get(key); } catch (ExecutionException e) { throw new UncheckedExecutionException(e.getCause()); } }
LoadingCache<Object, Object> cache = CaffeinatedGuava.build( Caffeine.newBuilder().recordStats().executor(MoreExecutors.directExecutor()), loader); CacheStats stats = cache.stats(); assertEquals(0, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); cache.get(new Object()); fail(); } catch (ExecutionException expected) { assertSame(e, expected.getCause()); stats = cache.stats(); assertEquals(1, stats.missCount()); assertEquals(0, stats.loadSuccessCount()); fail(); } catch (UncheckedExecutionException expected) { assertSame(e, expected.getCause()); fail(); } catch (ExecutionException expected) { assertSame(callableException, expected.getCause()); fail(); } catch (ExecutionException expected) { assertSame(e, expected.getCause());
final UncheckedExecutionException uee = new UncheckedExecutionException(cause); final ExecutionException ee = new ExecutionException(cause); cacheUnchecked.get(new Object()); fail(); } catch (UncheckedExecutionException caughtEe) { assertSame(uee, caughtEe.getCause()); cacheUnchecked.getUnchecked(new Object()); fail(); } catch (UncheckedExecutionException caughtUee) { assertSame(uee, caughtUee.getCause()); cacheUnchecked.refresh(new Object()); checkLoggedCause(uee); fail(); } catch (UncheckedExecutionException caughtEe) { assertSame(uee, caughtEe.getCause()); fail(); } catch (ExecutionException caughtEe) { assertSame(ee, caughtEe.getCause()); fail(); } catch (UncheckedExecutionException caughtUee) { assertSame(ee, caughtUee.getCause());
/** * Flattens a class's type hierarchy into a set of {@code Class} objects including all * superclasses (transitively) and all interfaces implemented by these superclasses. */ @VisibleForTesting static ImmutableSet<Class<?>> flattenHierarchy(Class<?> concreteClass) { try { return flattenHierarchyCache.getUnchecked(concreteClass); } catch (UncheckedExecutionException e) { throw Throwables.propagate(e.getCause()); } }
Throwable cause = ee.getCause(); if (cause instanceof Error) { throw new ExecutionError((Error) cause); } else if (cause instanceof RuntimeException) { throw new UncheckedExecutionException(cause);
public void testBulkLoadingExceptionWithCause() throws ExecutionException { final Exception cause = new Exception(); final UncheckedExecutionException uee = new UncheckedExecutionException(cause); final ExecutionException ee = new ExecutionException(cause); LoadingCache<Object, Object> cacheUnchecked = CaffeinatedGuava.build(Caffeine.newBuilder(), bulkLoader(exceptionLoader(uee))); LoadingCache<Object, Object> cacheChecked = CaffeinatedGuava.build(Caffeine.newBuilder(), bulkLoader(exceptionLoader(ee))); try { cacheUnchecked.getAll(asList(new Object())); fail(); } catch (UncheckedExecutionException caughtEe) { assertSame(uee, caughtEe.getCause()); } try { cacheChecked.getAll(asList(new Object())); fail(); } catch (ExecutionException caughtEe) { assertSame(ee, caughtEe.getCause()); } }
private void wrapAndThrowExecutionExceptionOrError(Throwable cause) throws ExecutionException { if (cause instanceof Error) { throw new ExecutionError((Error) cause); } else if (cause instanceof RuntimeException) { throw new UncheckedExecutionException(cause); } else { throw new ExecutionException(cause); } }
if (mod == 0) { assertTrue(result.get(i) instanceof ExecutionException); assertSame(e, ((ExecutionException) result.get(i)).getCause()); } else { assertTrue(result.get(i) instanceof UncheckedExecutionException); assertSame(e, ((UncheckedExecutionException) result.get(i)).getCause()); cache.getUnchecked("bar"); fail(); } catch (UncheckedExecutionException expected) {
@Override public ListenableFuture<DriveInfo> apply(String input) { try { return Futures.immediateFuture(cache.getUnchecked(input)); } catch (CacheLoader.InvalidCacheLoadException e) { logger.debug("drive %s not found", input); } catch (UncheckedExecutionException e) { logger.warn(e, "error finding drive %s: %s", input, e.getMessage()); } return Futures.immediateFuture(null); }
private static <K, V> V get(LoadingCache<K, V> cache, K key) { try { return cache.getUnchecked(key); } catch (UncheckedExecutionException e) { throwIfInstanceOf(e.getCause(), PrestoException.class); throw e; } }
final UncheckedExecutionException uee = new UncheckedExecutionException(cause); final ExecutionException ee = new ExecutionException(cause); cacheUnchecked.get(new Object()); fail(); } catch (ExecutionException e) { cacheUnchecked.getUnchecked(new Object()); fail(); } catch (UncheckedExecutionException caughtUee) { cacheUnchecked.refresh(new Object()); checkLoggedCause(uee);
public boolean login(String username, String password) { try { Credentials key = new Credentials(username, password); authenticationCache.refresh(key); authenticationCache.get(key); } catch (UncheckedExecutionException e) { throw Throwables.propagate(e.getCause()); } catch (ExecutionException e) { return false; } return true; }
@Override public void checkAccess(int userId) { try (Handle handle = dbi.open()) { Boolean exists = handle.createQuery("select email, password from web_user where id = :id") .bind("id", userId).map((index, r, ctx) -> { String email = r.getString(1); String password = r.getString(2); try { Principal principal = authenticationCache.get(new Credentials(email, password)); if (principal == null) { throw new RakamException("LDAP user doesn't exist", FORBIDDEN); } } catch (UncheckedExecutionException e) { throw Throwables.propagate(e.getCause()); } catch (ExecutionException e) { throw new RakamException("LDAP user doesn't exist", FORBIDDEN); } return Boolean.TRUE; }).first(); if (!Boolean.TRUE.equals(exists)) { throw new RakamException("LDAP user doesn't exist in database", FORBIDDEN); } } }
@Override public Type getType(TypeSignature signature) { Type type = types.get(signature); if (type == null) { try { return parametricTypeCache.getUnchecked(signature); } catch (UncheckedExecutionException e) { throwIfUnchecked(e.getCause()); throw new RuntimeException(e.getCause()); } } return type; }
public static InferredNullability getInferredNullability(Tree methodOrInitializerOrLambda) { checkArgument( methodOrInitializerOrLambda instanceof MethodTree || methodOrInitializerOrLambda instanceof LambdaExpressionTree || methodOrInitializerOrLambda instanceof BlockTree || methodOrInitializerOrLambda instanceof VariableTree, "Tree `%s` is not a lambda, initializer, or method.", methodOrInitializerOrLambda); try { return inferenceCache.getUnchecked(methodOrInitializerOrLambda); } catch (UncheckedExecutionException e) { throw e.getCause() instanceof CompletionFailure ? (CompletionFailure) e.getCause() : e; } }
@Override public V get(K key) { try { return cache.get(key); } catch (UncheckedExecutionException e) { if (e.getCause() instanceof CacheMissException) { return null; } throw (RuntimeException) e.getCause(); } catch (ExecutionException e) { throw new CompletionException(e); } catch (ExecutionError e) { throw (Error) e.getCause(); } }
public void testBulkLoadingExceptionWithCause() { final Exception cause = new Exception(); final UncheckedExecutionException uee = new UncheckedExecutionException(cause); final ExecutionException ee = new ExecutionException(cause); LoadingCache<Object, Object> cacheUnchecked = CacheBuilder.newBuilder().build(bulkLoader(exceptionLoader(uee))); LoadingCache<Object, Object> cacheChecked = CacheBuilder.newBuilder().build(bulkLoader(exceptionLoader(ee))); try { cacheUnchecked.getAll(asList(new Object())); fail(); } catch (ExecutionException e) { fail(); } catch (UncheckedExecutionException caughtEe) { assertThat(caughtEe).hasCauseThat().isSameAs(uee); } try { cacheChecked.getAll(asList(new Object())); fail(); } catch (ExecutionException caughtEe) { assertThat(caughtEe).hasCauseThat().isSameAs(ee); } }
private static <K, V> Map<K, V> getAll(LoadingCache<K, V> cache, Iterable<K> keys) { try { return cache.getAll(keys); } catch (ExecutionException | UncheckedExecutionException e) { throwIfInstanceOf(e.getCause(), PrestoException.class); throwIfUnchecked(e); throw new UncheckedExecutionException(e); } }