/** * Check "javax.servlet.error.exception" attribute for a multipart exception. */ private boolean hasMultipartException(HttpServletRequest request) { Throwable error = (Throwable) request.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE); while (error != null) { if (error instanceof MultipartException) { return true; } error = error.getCause(); } return false; }
private List<Throwable> getListOfCauses(Throwable ex) { List<Throwable> list = new ArrayList<Throwable>(); Throwable root = ex.getCause(); if (root == null || root == ex) { return list; } else { while (true) { list.add(root); Throwable cause = root.getCause(); if (cause == null || cause == root) { return list; } else { root = cause; } } } }
/** * Check the source behind this error: possibly an {@link Exception} * (typically {@link org.springframework.beans.PropertyAccessException}) * or a Bean Validation {@link javax.validation.ConstraintViolation}. * <p>The cause of the outermost exception will be introspected as well, * e.g. the underlying conversion exception or exception thrown from a setter * (instead of having to unwrap the {@code PropertyAccessException} in turn). * @return whether this error has been caused by a source object of the given type * @since 5.0.4 */ public boolean contains(Class<?> sourceType) { return (sourceType.isInstance(this.source) || (this.source instanceof Throwable && sourceType.isInstance(((Throwable) this.source).getCause()))); }
private void appendStackTrace(StringBuilder b, Throwable ex, String prefix) { b.append(prefix).append(ex).append('\n'); for (StackTraceElement stackElement : ex.getStackTrace()) { b.append("\t\tat ").append(stackElement).append('\n'); } if (ex.getCause() != null) { b.append("\tCaused by: "); appendStackTrace(b, ex.getCause(), ""); } }
@Override protected int getErrorCode(Throwable e) { if (e instanceof Fault) { e = e.getCause(); } if (e instanceof SocketTimeoutException) { return RpcException.TIMEOUT_EXCEPTION; } else if (e instanceof IOException) { return RpcException.NETWORK_EXCEPTION; } return super.getErrorCode(e); }
@Override protected int getErrorCode(Throwable e) { if (e instanceof Fault) { e = e.getCause(); } if (e instanceof SocketTimeoutException) { return RpcException.TIMEOUT_EXCEPTION; } else if (e instanceof IOException) { return RpcException.NETWORK_EXCEPTION; } return super.getErrorCode(e); }
/** * Appends the chain of messages from the {@code conflictingStackTrace} to the original {@code * message}. */ @Override public String getMessage() { StringBuilder message = new StringBuilder(super.getMessage()); for (Throwable t = conflictingStackTrace; t != null; t = t.getCause()) { message.append(", ").append(t.getMessage()); } return message.toString(); } }
private static void rethrow(ExecutionException e) throws ExecutionException { Throwable wrapper = e.getCause(); if (wrapper instanceof WrapperException) { Throwable cause = wrapper.getCause(); if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } else if (cause instanceof Error) { throw (Error) cause; } } throw e; }
@Nullable private HttpStatus resolveStatus(Throwable ex) { HttpStatus status = determineStatus(ex); if (status == null) { Throwable cause = ex.getCause(); if (cause != null) { status = resolveStatus(cause); } } return status; }
@Override public boolean matches(Object item) { Throwable cause = null; if (item != null && item instanceof Throwable) { cause = ((Throwable)item).getCause(); } return matcher.matches(cause); }
private static void filterRecursive(Throwable th) { try { filter(th); } catch (Exception e) { // ignore filter exceptions } Throwable cause = th.getCause(); if (cause != null) { filterRecursive(cause); } }
public static void assertUndeliverable(List<Throwable> list, int index, Class<? extends Throwable> clazz) { Throwable ex = list.get(index); if (!(ex instanceof UndeliverableException)) { AssertionError err = new AssertionError("Outer exception UndeliverableException expected but got " + list.get(index)); err.initCause(list.get(index)); throw err; } ex = ex.getCause(); if (!clazz.isInstance(ex)) { AssertionError err = new AssertionError("Inner exception " + clazz + " expected but got " + list.get(index)); err.initCause(list.get(index)); throw err; } }
/** * Cast the given Throwable to CompositeException and returns its inner * Throwable list. * @param ex the target Throwable * @return the list of Throwables */ public static List<Throwable> compositeList(Throwable ex) { if (ex instanceof UndeliverableException) { ex = ex.getCause(); } return ((CompositeException)ex).getExceptions(); }
@Test public void nullRootCause() { RuntimeException te = new RuntimeException() { private static final long serialVersionUID = -8492568224555229753L; @Override public Throwable getCause() { return null; } }; assertSame(te, new CompositeException(te).getCause().getCause()); assertSame(te, new CompositeException(new RuntimeException(te)).getCause().getCause().getCause()); }
@Override public void onError(Throwable e) { String trace = stackTraceAsString(e); System.out.println("On Error: " + trace); assertTrue(trace, trace.contains("OnNextValue")); assertTrue("No Cause on throwable" + e, e.getCause() != null); // assertTrue(e.getCause().getClass().getSimpleName() + " no OnNextValue", // e.getCause() instanceof OnErrorThrowable.OnNextValue); }
@After public void after() { RxJavaPlugins.reset(); assertFalse("" + errors, errors.isEmpty()); TestHelper.assertError(errors, 0, OnErrorNotImplementedException.class); Throwable c = errors.get(0).getCause(); assertTrue("" + c, c instanceof TestException); }
@Test public void subscribeZeroError() { List<Throwable> errors = TestHelper.trackPluginErrors(); try { assertTrue(Maybe.error(new TestException()) .subscribe().isDisposed()); TestHelper.assertError(errors, 0, OnErrorNotImplementedException.class); Throwable c = errors.get(0).getCause(); assertTrue("" + c, c instanceof TestException); } finally { RxJavaPlugins.reset(); } }