Skip to content
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

Fix bug in CompositeException.getRootCause #6380

Merged
merged 2 commits into from
Jan 21, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public int size() {
*/
/*private */Throwable getRootCause(Throwable e) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should go ahead and make it static

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, already merged.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just post a new PR.

Throwable root = e.getCause();
if (root == null || cause == root) {
if (root == null || e == root) {
return e;
}
while (true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,22 @@ public synchronized Throwable getCause() {
}
};
CompositeException ex = new CompositeException(throwable);
assertSame(ex, ex.getRootCause(ex));
assertSame(ex0, ex.getRootCause(ex));
}

@Test
public void rootCauseSelf() {
Throwable throwable = new Throwable() {

private static final long serialVersionUID = -4398003222998914415L;

@Override
public synchronized Throwable getCause() {
return this;
}
};
CompositeException tmp = new CompositeException(new TestException());
assertSame(throwable, tmp.getRootCause(throwable));
}
}

Expand Down