Skip to content

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

Merged
stevegury merged 1 commit intoReactiveX:1.xfrom
zsxwing:fix-3679
Jun 1, 2016
Merged

1.x: Use the correct Throwable to set the cause for CompositeException#3977
stevegury merged 1 commit intoReactiveX:1.xfrom
zsxwing:fix-3679

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
Contributor

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.

4 participants