File tree Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -49,12 +49,19 @@ public final class CompositeException extends RuntimeException {
49
49
public CompositeException (String messagePrefix , Collection <? extends Throwable > errors ) {
50
50
Set <Throwable > deDupedExceptions = new LinkedHashSet <Throwable >();
51
51
List <Throwable > _exceptions = new ArrayList <Throwable >();
52
- for (Throwable ex : errors ) {
53
- if (ex instanceof CompositeException ) {
54
- deDupedExceptions .addAll (((CompositeException ) ex ).getExceptions ());
55
- } else {
56
- deDupedExceptions .add (ex );
52
+ if (errors != null ) {
53
+ for (Throwable ex : errors ) {
54
+ if (ex instanceof CompositeException ) {
55
+ deDupedExceptions .addAll (((CompositeException ) ex ).getExceptions ());
56
+ } else
57
+ if (ex != null ) {
58
+ deDupedExceptions .add (ex );
59
+ } else {
60
+ deDupedExceptions .add (new NullPointerException ());
61
+ }
57
62
}
63
+ } else {
64
+ deDupedExceptions .add (new NullPointerException ());
58
65
}
59
66
60
67
_exceptions .addAll (deDupedExceptions );
Original file line number Diff line number Diff line change @@ -165,4 +165,17 @@ private static Throwable getRootCause(Throwable ex) {
165
165
}
166
166
}
167
167
}
168
+
169
+ @ Test
170
+ public void testNullCollection () {
171
+ CompositeException composite = new CompositeException (null );
172
+ composite .getCause ();
173
+ composite .printStackTrace ();
174
+ }
175
+ @ Test
176
+ public void testNullElement () {
177
+ CompositeException composite = new CompositeException (Arrays .asList ((Throwable )null ));
178
+ composite .getCause ();
179
+ composite .printStackTrace ();
180
+ }
168
181
}
You can’t perform that action at this time.
0 commit comments