-
Notifications
You must be signed in to change notification settings - Fork 7.6k
CompositeException extra NPE protection #3048
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,12 +49,19 @@ public final class CompositeException extends RuntimeException { | |
public CompositeException(String messagePrefix, Collection<? extends Throwable> errors) { | ||
Set<Throwable> deDupedExceptions = new LinkedHashSet<Throwable>(); | ||
List<Throwable> _exceptions = new ArrayList<Throwable>(); | ||
for (Throwable ex : errors) { | ||
if (ex instanceof CompositeException) { | ||
deDupedExceptions.addAll(((CompositeException) ex).getExceptions()); | ||
} else { | ||
deDupedExceptions.add(ex); | ||
if (errors != null) { | ||
for (Throwable ex : errors) { | ||
if (ex instanceof CompositeException) { | ||
deDupedExceptions.addAll(((CompositeException) ex).getExceptions()); | ||
} else | ||
if (ex != null) { | ||
deDupedExceptions.add(ex); | ||
} else { | ||
deDupedExceptions.add(new NullPointerException()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about just throwing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like throwing exception from an exception? Since you only have the option to detect null here, throwing an NPE would have the same stacktrace as these new NPEs, but with the exception that they will further 'crash' the application. In my way, these inconsistencies get captured and propagated with the CompositeException itself. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. |
||
} | ||
} | ||
} else { | ||
deDupedExceptions.add(new NullPointerException()); | ||
} | ||
|
||
_exceptions.addAll(deDupedExceptions); | ||
|
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.
Could you move
if (ex != null) {
to the same line ofelse
?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.
No. This is my style of coding and there is no style guide for RxJava anyway.
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.
I thought it was unintentional. Never mind. See this style for the first time :)