/** * @param toThrow The throwable that will be thrown, unwrapped and unchecked; must not be null * @throws NullPointerException if toThrow is null */ public static void throwUnchecked(final Throwable toThrow) { throwUnchecked(toThrow, null); }
@Override public Properties apply(final InputStream propertyResource) { try (InputStream closablePropertyResource = propertyResource) { final Properties loadedProperties = new Properties(); loadedProperties.load(closablePropertyResource); return loadedProperties; } catch (IOException ioException) { return throwUnchecked(ioException, null); } } };
@Override public Properties apply(final InputStream propertyResource) { try (InputStream closablePropertyResource = propertyResource) { final Properties loadedProperties = new Properties(); loadedProperties.load(closablePropertyResource); return loadedProperties; } catch (IOException ioException) { return throwUnchecked(ioException, null); } } };
private FluentIterable<FieldFacade> fields() { try { return IDENTITY_FIELDS.get(getClass()); } catch (ExecutionException e) { return throwUnchecked(e.getCause(), null); } }
@Override protected Throwable featureValueOf(final Constructor<?> constructor) { try { constructor.setAccessible(true); constructor.newInstance(); return null; } catch (InvocationTargetException e) { return e.getCause(); } catch (Exception e) { return throwUnchecked(e, null); } finally { constructor.setAccessible(false); } } };
/** * @throws Exception thrown by {@link #perform()} - unchecked */ @Override public final void run() { try { perform(); } catch (Exception e) { throwUnchecked(e); } }
private static <T> T doWithSystemClasses(Callable<T> callable) throws SysOutOverSLF4JSystemJarNotPresentException { try { return callable.call(); } catch (NoClassDefFoundError error) { if (error.getMessage().contains("sysoutslf4j/system")) { throw new SysOutOverSLF4JSystemJarNotPresentException(error); } else { throw error; } } catch (Exception e) { return throwUnchecked(e, null); } }
/** * @throws Exception thrown by the original caller, unwrapped * @return the result of the expression passed to the constructor; this is evaluated the first time this method is called, * subsequent calls return the same result without re-evaluating it. Concurrent calls block until the first execution * is complete. */ @Override public T call() { supplier.run(); try { return getUninterruptibly(supplier); } catch (ExecutionException e) { return throwUnchecked(e.getCause(), null); } }
@SuppressWarnings({ "unchecked", "PMD.AvoidCatchingThrowable" }) private static <ThrowableType extends Throwable> ThrowableType shouldThrow( final Class<ThrowableType> expectedThrowableType, final Optional<String> message, final Runnable workThatShouldThrowThrowable) { try { workThatShouldThrowThrowable.run(); throw new AssertionError(message.or("No exception thrown")); } catch (final Throwable actualThrowableThrown) { final Throwable trueThrowable = extractTrueThrowable(expectedThrowableType, actualThrowableThrown); if (!expectedThrowableType.isInstance(trueThrowable)) { throwUnchecked(actualThrowableThrown); } return (ThrowableType) trueThrowable; } }