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

1.x: Use the correct Throwable to set the cause for CompositeException #3977

Merged
merged 1 commit into from
Jun 1, 2016

Conversation

zsxwing
Copy link
Member

@zsxwing zsxwing commented Jun 1, 2016

The cause of #3679 is we use a wrong Throwable (its cause has been set) to set the cause and initCause will throw an exception. Hence, the cause chain is not created correctly. In this PR, it searches the root cause (which doesn't have a cause) and use it to call initCause.

return e;
} else {
while(true) {
if (root.getCause() == null) {
Copy link
Member

Choose a reason for hiding this comment

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

I have seen cases where a Throwable will return this for getCause() which can cause infinite loops in code like this.

I think you want:

while (true) {
  Throwable cause = root.getCause();
  if (cause == null || cause == root) {
    return root;
  }
  root = cause;
}

as a result instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was concerned it too but didn't do it because the default getCause will return null when the inner cause field is this.

However, getCause can be override so it's still possible. Will update it.

The cause of ReactiveX#3679 is we use a wrong Throwable (its cause has been set) to set the cause and `initCause` will throw an exception. Hence, the cause chain is not created correctly. In this PR, it searches the root cause (which doesn't have a cause) and use it to call `initCause`.
@akarnokd
Copy link
Member

akarnokd commented Jun 1, 2016

👍

1 similar comment
@stevegury
Copy link
Member

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants