Skip to content

Composite exception should update cause to match the correct throwable that's first in the chain #3963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion src/main/java/rx/exceptions/CompositeException.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public synchronized Throwable getCause() {
chain = e;
}
}
cause = _cause;
cause = !exceptions.isEmpty() ? exceptions.get(0) : _cause;
}
return cause;
}
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/rx/exceptions/CompositeExceptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ public void testMultipleWithSameCause() {
assertNotNull(getRootCause(ce));
System.err.println("----------------------------- print cause stacktrace");
ce.getCause().printStackTrace();

assertEquals(e1, ce.getCause());
}

@Test(timeout = 1000)
public void testCompositeExceptionCause() {
Throwable error = new Throwable("TheCause");
CompositeException ce = new CompositeException(error);

System.err.println("----------------------------- print composite stacktrace");
ce.printStackTrace();

assertNoCircularReferences(ce);
assertNotNull(getRootCause(ce));
System.err.println("----------------------------- print cause stacktrace");
ce.getCause().printStackTrace();

assertEquals(error, ce.getCause());
}

@Test(timeout = 1000)
Expand Down