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

2.x: Make CompositeExcpetion thread-safe like 1.x and also fix some issues #4619

Merged
merged 1 commit into from
Sep 28, 2016

Conversation

zsxwing
Copy link
Member

@zsxwing zsxwing commented Sep 28, 2016

Right now CompositeExcpetion has several issues:

  • CompositeException(Throwable... exceptions) doesn't deduplicate exceptions and flatten CompositeExceptions like CompositeException(Iterable<? extends Throwable> errors)
  • If using CompositeException(Iterable<? extends Throwable> errors) to create CompositeException, suppress cannot be used.
  • suppress doesn't update cause.
  • suppress doesn't deduplicate exceptions and flatten CompositeExceptions.
  • suppress and Throwable.addSuppressed are pretty confusing for Java 7+ users. Without looking at the implementation, it's hard to figure out the differences.

This PR made the following changes:

  • Remove CompositeException.suppress so that it's easy to make CompositeException thread-safe.
    • This may cause some performance lost in some path rarely happening, e.g., an excpetion is thrown from onError, but that's not a big deal.
    • Since suppress is removed, it doesn't make sense to create an empty CompositeException, so isEmpty is removed and defense codes are added.
  • Defense codes for bad exceptions.
  • Deduplicate excepctions and flatten CompositeExceptions for CompositeException(Throwable... exceptions).

…ssues.

Right now CompositeExcpetion has several issues:

- `CompositeException(Throwable... exceptions)` doesn't deduplicate exceptions and flatten CompositeExceptions like `CompositeException(Iterable<? extends Throwable> errors)`
- If using `CompositeException(Iterable<? extends Throwable> errors)` to create CompositeException, `suppress` cannot be used.
- `suppress` doesn't update `cause`.
- `suppress` doesn't deduplicate exceptions and flatten CompositeExceptions.
- `suppress` and `Throwable.addSuppressed` are pretty confusing for Java 7+ users. Without looking at the implementation, it's hard to figure out the differences.

This PR made the following changes:

- Remove `CompositeException.suppress` so that it's easy to make CompositeException thread-safe.
  - This may cause some performance lost in some path rarely happening, e.g., an excpetion is thrown from `onError`, but that's not a big deal.
  - Since `suppress` is removed, it doesn't make sense to create an empty CompositeException, so `isEmpty` is removed and defense codes are added.
- Defense codes for bad exceptions.
- Deduplicate excepctions and flatten CompositeExceptions for `CompositeException(Throwable... exceptions)`.
@codecov-io
Copy link

codecov-io commented Sep 28, 2016

Current coverage is 78.12% (diff: 68.75%)

Merging #4619 into 2.x will decrease coverage by <.01%

@@                2.x      #4619   diff @@
==========================================
  Files           557        557          
  Lines         36296      36284    -12   
  Methods           0          0          
  Messages          0          0          
  Branches       5567       5566     -1   
==========================================
- Hits          28359      28346    -13   
+ Misses         5926       5925     -1   
- Partials       2011       2013     +2   

Powered by Codecov. Last update 534fc67...f94dfad

@akarnokd akarnokd added this to the 2.0 RC4 milestone Sep 28, 2016
@@ -266,15 +244,16 @@ public String getMessage() {
private List<Throwable> getListOfCauses(Throwable ex) {
List<Throwable> list = new ArrayList<Throwable>();
Throwable root = ex.getCause();
if (root == null) {
if (root == null || root == ex) {
Copy link
Member

Choose a reason for hiding this comment

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

Do you have a test for this? I removed it because code coverage showed it as never taken.

Copy link
Member Author

Choose a reason for hiding this comment

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

}
if (!ce.isEmpty()) {
if (!errors.isEmpty()) {
CompositeException ce = new CompositeException(errors);
Copy link
Member

Choose a reason for hiding this comment

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

Might be worth changing this so when there is only one exception, it doesn't wrap and lenghten the stacktrace unnecessarily.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in #4631

@akarnokd akarnokd merged commit c3a1d91 into ReactiveX:2.x Sep 28, 2016
@zsxwing zsxwing deleted the composite-exception branch September 28, 2016 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants