@Test public void getCause_withChainOfSameType() { final RuntimeException rootCause = new RuntimeException("Oops"); final RuntimeException err = new RuntimeException(rootCause); assertThat(ExceptionUtil.getCause(err, RuntimeException.class)).contains(err); }
@SuppressWarnings("unchecked") public static <T extends Throwable> Optional<T> getCause( final Throwable err, Class<T> targetType) { return ExceptionUtils.getThrowableList(err).stream() .filter(targetType::isInstance) .map(e -> (T) e) .findFirst(); }
ExceptionUtil { @SuppressWarnings("unchecked") public static <T extends Throwable> Optional<T> getCause( final Throwable err, Class<T> targetType) { return ExceptionUtils.getThrowableList(err).stream() .filter(targetType::isInstance) .map(e -> (T) e) .findFirst(); } }
ExceptionUtil { @SuppressWarnings("unchecked") public static <T extends Throwable> Optional<T> getCause( final Throwable err, Class<T> targetType) { return ExceptionUtils.getThrowableList(err).stream() .filter(targetType::isInstance) .map(e -> (T) e) .findFirst(); }  }
ExceptionUtil { @SuppressWarnings("unchecked") public static <T extends Throwable> Optional<T> getCause( final Throwable err, Class<T> targetType) { return ExceptionUtils.getThrowableList(err).stream() .filter(targetType::isInstance) .map(e -> (T) e) .findFirst(); }  @SuppressWarnings("unchecked") static Optional<T> getCause(
      final Throwable err, Class<T> targetType); }
ExceptionUtil { @SuppressWarnings("unchecked") public static <T extends Throwable> Optional<T> getCause( final Throwable err, Class<T> targetType) { return ExceptionUtils.getThrowableList(err).stream() .filter(targetType::isInstance) .map(e -> (T) e) .findFirst(); }  @SuppressWarnings("unchecked") static Optional<T> getCause(
      final Throwable err, Class<T> targetType);  }