@Test public void testNullCause() { RuntimeException t = new RuntimeException(); assertNull("If no cause found it should return with null", ThrowableUtil.getSpecificCauseRecursively(t, ConstraintViolationException.class)); }
public static <T> T getSpecificCauseRecursively(Throwable t, Class<T> causeType) { if (causeType.isInstance(t)) { return causeType.cast(t); } else if (t == null) { return null; } return getSpecificCauseRecursively(t.getCause(), causeType); }
ThrowableUtil { public static <T> T getSpecificCauseRecursively(Throwable t, Class<T> causeType) { if (causeType.isInstance(t)) { return causeType.cast(t); } else if (t == null) { return null; } return getSpecificCauseRecursively(t.getCause(), causeType); } }
ThrowableUtil { public static <T> T getSpecificCauseRecursively(Throwable t, Class<T> causeType) { if (causeType.isInstance(t)) { return causeType.cast(t); } else if (t == null) { return null; } return getSpecificCauseRecursively(t.getCause(), causeType); } private  ThrowableUtil(); }
ThrowableUtil { public static <T> T getSpecificCauseRecursively(Throwable t, Class<T> causeType) { if (causeType.isInstance(t)) { return causeType.cast(t); } else if (t == null) { return null; } return getSpecificCauseRecursively(t.getCause(), causeType); } private  ThrowableUtil(); static T getSpecificCauseRecursively(Throwable t, Class<T> causeType); }
ThrowableUtil { public static <T> T getSpecificCauseRecursively(Throwable t, Class<T> causeType) { if (causeType.isInstance(t)) { return causeType.cast(t); } else if (t == null) { return null; } return getSpecificCauseRecursively(t.getCause(), causeType); } private  ThrowableUtil(); static T getSpecificCauseRecursively(Throwable t, Class<T> causeType);  }