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 {
4949 public CompositeException (String messagePrefix , Collection <? extends Throwable > errors ) {
5050 Set <Throwable > deDupedExceptions = new LinkedHashSet <Throwable >();
5151 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+ }
5762 }
63+ } else {
64+ deDupedExceptions .add (new NullPointerException ());
5865 }
5966
6067 _exceptions .addAll (deDupedExceptions );
Original file line number Diff line number Diff line change @@ -165,4 +165,17 @@ private static Throwable getRootCause(Throwable ex) {
165165 }
166166 }
167167 }
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+ }
168181}
You can’t perform that action at this time.
0 commit comments