@Test public void findCauseNotFound() { final IllegalArgumentException exception = new IllegalArgumentException( "Test", new PatternSyntaxException( "Test", "xxx", 1 ) ); Assert.assertNull( ExceptionUtils.findCause( exception, NumberFormatException.class ) ); }
@Nullable public static Throwable findCause( @Nonnull Throwable exception, @Nonnull Class<?>... causeClasses ) { final Set<Throwable> checkedCauses = new HashSet<>(); Throwable cause = exception; do { if ( isInstance( cause, causeClasses ) ) { break; } checkedCauses.add( cause ); cause = cause.getCause(); } while ( (cause != null) && !checkedCauses.contains( cause ) ); return cause; }
ExceptionUtils { @Nullable public static Throwable findCause( @Nonnull Throwable exception, @Nonnull Class<?>... causeClasses ) { final Set<Throwable> checkedCauses = new HashSet<>(); Throwable cause = exception; do { if ( isInstance( cause, causeClasses ) ) { break; } checkedCauses.add( cause ); cause = cause.getCause(); } while ( (cause != null) && !checkedCauses.contains( cause ) ); return cause; } }
ExceptionUtils { @Nullable public static Throwable findCause( @Nonnull Throwable exception, @Nonnull Class<?>... causeClasses ) { final Set<Throwable> checkedCauses = new HashSet<>(); Throwable cause = exception; do { if ( isInstance( cause, causeClasses ) ) { break; } checkedCauses.add( cause ); cause = cause.getCause(); } while ( (cause != null) && !checkedCauses.contains( cause ) ); return cause; } private  ExceptionUtils(); }
ExceptionUtils { @Nullable public static Throwable findCause( @Nonnull Throwable exception, @Nonnull Class<?>... causeClasses ) { final Set<Throwable> checkedCauses = new HashSet<>(); Throwable cause = exception; do { if ( isInstance( cause, causeClasses ) ) { break; } checkedCauses.add( cause ); cause = cause.getCause(); } while ( (cause != null) && !checkedCauses.contains( cause ) ); return cause; } private  ExceptionUtils(); @Nullable static Throwable findCause( @Nonnull Throwable exception, @Nonnull Class<?>... causeClasses ); }
ExceptionUtils { @Nullable public static Throwable findCause( @Nonnull Throwable exception, @Nonnull Class<?>... causeClasses ) { final Set<Throwable> checkedCauses = new HashSet<>(); Throwable cause = exception; do { if ( isInstance( cause, causeClasses ) ) { break; } checkedCauses.add( cause ); cause = cause.getCause(); } while ( (cause != null) && !checkedCauses.contains( cause ) ); return cause; } private  ExceptionUtils(); @Nullable static Throwable findCause( @Nonnull Throwable exception, @Nonnull Class<?>... causeClasses );  }