@Override public void onError(Throwable t) { Throwable e = error; if (e == null) { actual.onError(t); } else { actual.onError(new CompositeException(e, t)); } }
@Override public void onError(Throwable e) { try { onEvent.accept(e); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); e = new CompositeException(e, ex); } observer.onError(e); }
@Override public void onError(Throwable e) { lazySet(DisposableHelper.DISPOSED); try { onError.accept(e); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); RxJavaCommonPlugins.onError(new CompositeException(e, ex)); } }
@Override public void onError(Throwable e) { try { lazySet(DisposableHelper.DISPOSED); onCallback.accept(null, e); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); RxJavaCommonPlugins.onError(new CompositeException(e, ex)); } }
@Override public void onError(Throwable e) { lazySet(DisposableHelper.DISPOSED); try { onError.accept(e); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); RxJavaCommonPlugins.onError(new CompositeException(e, ex)); } }
@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()); }
@Test public void badException() { Throwable e = new BadException(); assertSame(e, new CompositeException(e).getCause().getCause()); assertSame(e, new CompositeException(new RuntimeException(e)).getCause().getCause().getCause()); } }
@Override public void onError(Throwable t) { R p; try { p = ObjectHelper.requireNonNull(onErrorMapper.apply(t), "The onError publisher returned is null"); } catch (Throwable e) { Exceptions.throwIfFatal(e); actual.onError(new CompositeException(t, e)); return; } complete(p); }
@Override public void onError(Throwable t) { T v; try { v = ObjectHelper.requireNonNull(valueSupplier.apply(t), "The valueSupplier returned a null value"); } catch (Throwable ex) { Exceptions.throwIfFatal(ex); actual.onError(new CompositeException(t, ex)); return; } complete(v); }
@Test public void testNullElement() { CompositeException composite = new CompositeException(Collections.singletonList((Throwable) null)); composite.getCause(); composite.printStackTrace(); }
@Test public void constructorWithNull() { assertTrue(new CompositeException((Throwable[])null).getExceptions().get(0) instanceof NullPointerException); assertTrue(new CompositeException((Iterable<Throwable>)null).getExceptions().get(0) instanceof NullPointerException); assertTrue(new CompositeException(null, new TestException()).getExceptions().get(0) instanceof NullPointerException); }
@Test public void printStackTrace() { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); new CompositeException(new TestException()).printStackTrace(pw); assertTrue(sw.toString().contains("TestException")); }
@Override public void onError(Throwable e) { MaybeSource<? extends R> source; try { source = ObjectHelper.requireNonNull(onErrorMapper.apply(e), "The onErrorMapper returned a null MaybeSource"); } catch (Exception ex) { Exceptions.throwIfFatal(ex); actual.onError(new CompositeException(e, ex)); return; } source.subscribe(new InnerObserver()); }
@Test public void testNullCollection() { CompositeException composite = new CompositeException((List<Throwable>)null); composite.getCause(); composite.printStackTrace(); } @Test
@Test public void messageCollection() { CompositeException compositeException = new CompositeException(ex1, ex3); assertEquals("2 exceptions occurred. ", compositeException.getMessage()); }
@Test public void messageVarargs() { CompositeException compositeException = new CompositeException(ex1, ex2, ex3); assertEquals("3 exceptions occurred. ", compositeException.getMessage()); }
@Test(timeout = 1000) public void testCompositeExceptionFromChildThenParent() { CompositeException cex = new CompositeException(ex2, ex1); System.err.println("----------------------------- print composite stacktrace"); cex.printStackTrace(); assertEquals(2, cex.getExceptions().size()); assertNoCircularReferences(cex); assertNotNull(getRootCause(cex)); System.err.println("----------------------------- print cause stacktrace"); cex.getCause().printStackTrace(); }
@Test(timeout = 1000) public void testCompositeExceptionFromParentThenChild() { CompositeException cex = new CompositeException(ex1, ex2); System.err.println("----------------------------- print composite stacktrace"); cex.printStackTrace(); assertEquals(2, cex.getExceptions().size()); assertNoCircularReferences(cex); assertNotNull(getRootCause(cex)); System.err.println("----------------------------- print cause stacktrace"); cex.getCause().printStackTrace(); }
@Test(timeout = 1000) public void testCompositeExceptionFromCompositeAndChild() { CompositeException cex = new CompositeException(getNewCompositeExceptionWithEx123(), ex1); System.err.println("----------------------------- print composite stacktrace"); cex.printStackTrace(); assertEquals(3, cex.getExceptions().size()); assertNoCircularReferences(cex); assertNotNull(getRootCause(cex)); System.err.println("----------------------------- print cause stacktrace"); cex.getCause().printStackTrace(); }
@Test(timeout = 1000) public void testCompositeExceptionFromChildAndComposite() { CompositeException cex = new CompositeException(ex1, getNewCompositeExceptionWithEx123()); System.err.println("----------------------------- print composite stacktrace"); cex.printStackTrace(); assertEquals(3, cex.getExceptions().size()); assertNoCircularReferences(cex); assertNotNull(getRootCause(cex)); System.err.println("----------------------------- print cause stacktrace"); cex.getCause().printStackTrace(); }