/** * All of the following {@code printStackTrace} functionality is derived from JDK {@link Throwable} * {@code printStackTrace}. In particular, the {@code PrintStreamOrWriter} abstraction is copied wholesale. * * Changes from the official JDK implementation:<ul> * <li>no infinite loop detection</li> * <li>smaller critical section holding {@link PrintStream} lock</li> * <li>explicit knowledge about the exceptions {@link List} that this loops through</li> * </ul> */ @Override public void printStackTrace() { printStackTrace(System.err); }
/** * All of the following {@code printStackTrace} functionality is derived from JDK {@link Throwable} * {@code printStackTrace}. In particular, the {@code PrintStreamOrWriter} abstraction is copied wholesale. * * Changes from the official JDK implementation:<ul> * <li>no infinite loop detection</li> * <li>smaller critical section holding {@link PrintStream} lock</li> * <li>explicit knowledge about the exceptions {@link List} that this loops through</li> * </ul> */ @Override public void printStackTrace() { printStackTrace(System.err); }
/** * All of the following {@code printStackTrace} functionality is derived from JDK {@link Throwable} * {@code printStackTrace}. In particular, the {@code PrintStreamOrWriter} abstraction is copied wholesale. * * Changes from the official JDK implementation:<ul> * <li>no infinite loop detection</li> * <li>smaller critical section holding {@link PrintStream} lock</li> * <li>explicit knowledge about the exceptions {@link List} that this loops through</li> * </ul> */ @Override public void printStackTrace() { printStackTrace(System.err); }
@Override public void printStackTrace(PrintWriter s) { printStackTrace(new WrappedPrintWriter(s)); }
@Override public void printStackTrace(PrintWriter s) { printStackTrace(new WrappedPrintWriter(s)); }
@Override public void printStackTrace(PrintWriter s) { printStackTrace(new WrappedPrintWriter(s)); }
@Override public void printStackTrace(PrintStream s) { printStackTrace(new WrappedPrintStream(s)); }
@Override public void printStackTrace(PrintStream s) { printStackTrace(new WrappedPrintStream(s)); }
@Override public void printStackTrace(PrintStream s) { printStackTrace(new WrappedPrintStream(s)); }
@Test public void testNullElement() { CompositeException composite = new CompositeException(Collections.singletonList((Throwable) null)); composite.getCause(); composite.printStackTrace(); }
@Test public void printStackTrace() { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); new CompositeException(new TestException()).printStackTrace(pw); assertTrue(sw.toString().contains("TestException")); }
@Test(timeout = 1000) public void testMultipleWithSameCause() { Throwable rootCause = new Throwable("RootCause"); Throwable e1 = new Throwable("1", rootCause); Throwable e2 = new Throwable("2", rootCause); Throwable e3 = new Throwable("3", rootCause); CompositeException ce = new CompositeException(e1, e2, e3); System.err.println("----------------------------- print composite stacktrace"); ce.printStackTrace(); assertEquals(3, ce.getExceptions().size()); assertNoCircularReferences(ce); assertNotNull(getRootCause(ce)); System.err.println("----------------------------- print cause stacktrace"); ce.getCause().printStackTrace(); }
@Test public void testNullCollection() { CompositeException composite = new CompositeException((List<Throwable>)null); composite.getCause(); composite.printStackTrace(); } @Test
@Test(timeout = 1000) public void testCompositeExceptionFromTwoDuplicateComposites() { List<Throwable> exs = new ArrayList<Throwable>(); exs.add(getNewCompositeExceptionWithEx123()); exs.add(getNewCompositeExceptionWithEx123()); CompositeException cex = new CompositeException(exs); 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 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 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(); }
@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 testCompositeExceptionWithUnsupportedInitCause() { Throwable t = new Throwable() { private static final long serialVersionUID = -3282577447436848385L; @Override public synchronized Throwable initCause(Throwable cause) { throw new UnsupportedOperationException(); } }; CompositeException cex = new CompositeException(t, 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 testCompositeExceptionWithNullInitCause() { Throwable t = new Throwable("ThrowableWithNullInitCause") { private static final long serialVersionUID = -7984762607894527888L; @Override public synchronized Throwable initCause(Throwable cause) { return null; } }; CompositeException cex = new CompositeException(t, 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(); }