Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/rx/exceptions/CompositeException.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,13 @@ public synchronized Throwable getCause() {
// we now have 'e' as the last in the chain
try {
chain.initCause(e);
chain = chain.getCause();
} catch (Throwable t) {
// ignore
// the javadocs say that some Throwables (depending on how they're made) will never
// let me call initCause without blowing up even if it returns null
chain = e;
}
chain = chain.getCause();
}
cause = _cause;
}
Expand Down
42 changes: 42 additions & 0 deletions src/test/java/rx/exceptions/CompositeExceptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,46 @@ public void testNullElement() {
composite.getCause();
composite.printStackTrace();
}

@Test(timeout = 1000)
public void testCompositeExceptionWithUnsupportedInitCause() {
Throwable t = new Throwable() {
@Override
public synchronized Throwable initCause(Throwable cause) {
throw new UnsupportedOperationException();
}
};
CompositeException cex = new CompositeException(Arrays.asList(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") {
@Override
public synchronized Throwable initCause(Throwable cause) {
return null;
}
};
CompositeException cex = new CompositeException(Arrays.asList(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();
}
}