public static PrestoException internalError(Throwable t) { throwIfInstanceOf(t, Error.class); throwIfInstanceOf(t, PrestoException.class); return new PrestoException(StandardErrorCode.GENERIC_INTERNAL_ERROR, t); } }
private static <T> T doAs(Subject subject, GssSupplier<T> action) throws GSSException { try { return Subject.doAs(subject, (PrivilegedExceptionAction<T>) action::get); } catch (PrivilegedActionException e) { Throwable t = e.getCause(); throwIfInstanceOf(t, GSSException.class); throwIfUnchecked(t); throw new RuntimeException(t); } }
private static boolean invokeGetResult(MethodHandle getResultMethodHandle, int comparisonResult) { try { return (boolean) getResultMethodHandle.invokeExact(comparisonResult); } catch (Throwable t) { throwIfInstanceOf(t, Error.class); throwIfInstanceOf(t, PrestoException.class); throw new PrestoException(GENERIC_INTERNAL_ERROR, t); } }
@Override public int hashCode(long value) { try { return Long.hashCode((long) hashCodeHandle.invokeExact(value)); } catch (Throwable t) { throwIfInstanceOf(t, Error.class); throwIfInstanceOf(t, PrestoException.class); throw new PrestoException(GENERIC_INTERNAL_ERROR, t); } }
@Override public int hashCode(double value) { try { return Long.hashCode((long) hashCodeHandle.invokeExact(value)); } catch (Throwable t) { throwIfInstanceOf(t, Error.class); throwIfInstanceOf(t, PrestoException.class); throw new PrestoException(GENERIC_INTERNAL_ERROR, t); } }
public MongoTable getTable(SchemaTableName tableName) throws TableNotFoundException { try { return tableCache.getUnchecked(tableName); } catch (UncheckedExecutionException e) { throwIfInstanceOf(e.getCause(), PrestoException.class); throw e; } }
@Override public int hashCode(Object value) { try { return toIntExact(Long.hashCode((long) hashCodeHandle.invokeExact(value))); } catch (Throwable t) { throwIfInstanceOf(t, Error.class); throwIfInstanceOf(t, PrestoException.class); throw new PrestoException(GENERIC_INTERNAL_ERROR, t); } }
public List<File> getFiles(SchemaTableName table) { try { return cachedFiles.getUnchecked(table); } catch (UncheckedExecutionException e) { throwIfInstanceOf(e.getCause(), PrestoException.class); throw e; } }
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; } }
private SpecializedFunctionKey getSpecializedFunctionKey(Signature signature) { try { return specializedFunctionKeyCache.getUnchecked(signature); } catch (UncheckedExecutionException e) { throwIfInstanceOf(e.getCause(), PrestoException.class); throw e; } }
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); } }
@Override public Principal createAuthenticatedPrincipal(String user, String password) { try { return authenticationCache.getUnchecked(new Credentials(user, password)); } catch (UncheckedExecutionException e) { throwIfInstanceOf(e.getCause(), AccessDeniedException.class); throw e; } }
public InternalAggregationFunction getAggregateFunctionImplementation(Signature signature) { checkArgument(signature.getKind() == AGGREGATE, "%s is not an aggregate function", signature); checkArgument(signature.getTypeVariableConstraints().isEmpty(), "%s has unbound type parameters", signature); try { return specializedAggregationCache.getUnchecked(getSpecializedFunctionKey(signature)); } catch (UncheckedExecutionException e) { throwIfInstanceOf(e.getCause(), PrestoException.class); throw e; } }
public ScalarFunctionImplementation getScalarFunctionImplementation(Signature signature) { checkArgument(signature.getKind() == SCALAR, "%s is not a scalar function", signature); checkArgument(signature.getTypeVariableConstraints().isEmpty(), "%s has unbound type parameters", signature); try { return specializedScalarCache.getUnchecked(getSpecializedFunctionKey(signature)); } catch (UncheckedExecutionException e) { throwIfInstanceOf(e.getCause(), PrestoException.class); throw e; } }
public WindowFunctionSupplier getWindowFunctionImplementation(Signature signature) { checkArgument(signature.getKind() == WINDOW || signature.getKind() == AGGREGATE, "%s is not a window function", signature); checkArgument(signature.getTypeVariableConstraints().isEmpty(), "%s has unbound type parameters", signature); try { return specializedWindowCache.getUnchecked(getSpecializedFunctionKey(signature)); } catch (UncheckedExecutionException e) { throwIfInstanceOf(e.getCause(), PrestoException.class); throw e; } }
@GwtIncompatible // throwIfInstanceOf public void testThrowIfInstanceOf_null() throws SomeCheckedException { try { throwIfInstanceOf(null, SomeCheckedException.class); fail(); } catch (NullPointerException expected) { } }
@GwtIncompatible // throwIfInstanceOf public void testThrowIfInstanceOf_CheckedSubclass() { try { throwIfInstanceOf(new SomeCheckedException() {}, SomeCheckedException.class); fail(); } catch (SomeCheckedException expected) { } }
@GwtIncompatible // throwIfInstanceOf public void testThrowIfInstanceOf_Unchecked() throws SomeCheckedException { throwIfInstanceOf(new SomeUncheckedException(), SomeCheckedException.class); }
@GwtIncompatible // throwIfInstanceOf public void testThrowIfInstanceOf_CheckedDifferent() throws SomeCheckedException { throwIfInstanceOf(new SomeOtherCheckedException(), SomeCheckedException.class); }
@GwtIncompatible // throwIfInstanceOf public void testThrowIfInstanceOf_CheckedSame() { try { throwIfInstanceOf(new SomeCheckedException(), SomeCheckedException.class); fail(); } catch (SomeCheckedException expected) { } }