-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Conversation
…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)`.
Current coverage is 78.12% (diff: 68.75%)@@ 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
|
@@ -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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in #4631
Right now CompositeExcpetion has several issues:
CompositeException(Throwable... exceptions)
doesn't deduplicate exceptions and flatten CompositeExceptions likeCompositeException(Iterable<? extends Throwable> errors)
CompositeException(Iterable<? extends Throwable> errors)
to create CompositeException,suppress
cannot be used.suppress
doesn't updatecause
.suppress
doesn't deduplicate exceptions and flatten CompositeExceptions.suppress
andThrowable.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:
CompositeException.suppress
so that it's easy to make CompositeException thread-safe.onError
, but that's not a big deal.suppress
is removed, it doesn't make sense to create an empty CompositeException, soisEmpty
is removed and defense codes are added.CompositeException(Throwable... exceptions)
.