Skip to content

Commit 8611671

Browse files
committed
Merge pull request #3762 from vanniktech/dev_fix_composite_exception_message_prefix
1.x: Deprecate CompositeException constructor with message prefix
2 parents f8be5c1 + da44742 commit 8611671

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/main/java/rx/exceptions/CompositeException.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public final class CompositeException extends RuntimeException {
4141
private final List<Throwable> exceptions;
4242
private final String message;
4343

44+
/** @deprecated please use {@link #CompositeException(Collection)} */
45+
@Deprecated
4446
public CompositeException(String messagePrefix, Collection<? extends Throwable> errors) {
4547
Set<Throwable> deDupedExceptions = new LinkedHashSet<Throwable>();
4648
List<Throwable> _exceptions = new ArrayList<Throwable>();

src/main/java/rx/exceptions/Exceptions.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ public static void throwIfAny(List<? extends Throwable> exceptions) {
171171
throw new RuntimeException(t);
172172
}
173173
}
174-
throw new CompositeException(
175-
"Multiple exceptions", exceptions);
174+
throw new CompositeException(exceptions);
176175
}
177176
}
178177

src/test/java/rx/exceptions/CompositeExceptionTest.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.io.PrintStream;
2424
import java.util.ArrayList;
2525
import java.util.Arrays;
26+
import java.util.Collections;
2627
import java.util.List;
2728

2829
import org.junit.Test;
@@ -50,7 +51,7 @@ public void testMultipleWithSameCause() {
5051
Throwable e1 = new Throwable("1", rootCause);
5152
Throwable e2 = new Throwable("2", rootCause);
5253
Throwable e3 = new Throwable("3", rootCause);
53-
CompositeException ce = new CompositeException("3 failures with same root cause", Arrays.asList(e1, e2, e3));
54+
CompositeException ce = new CompositeException(Arrays.asList(e1, e2, e3));
5455

5556
System.err.println("----------------------------- print composite stacktrace");
5657
ce.printStackTrace();
@@ -174,7 +175,7 @@ public void testNullCollection() {
174175
}
175176
@Test
176177
public void testNullElement() {
177-
CompositeException composite = new CompositeException(Arrays.asList((Throwable)null));
178+
CompositeException composite = new CompositeException(Collections.singletonList((Throwable) null));
178179
composite.getCause();
179180
composite.printStackTrace();
180181
}
@@ -220,4 +221,16 @@ public synchronized Throwable initCause(Throwable cause) {
220221
System.err.println("----------------------------- print cause stacktrace");
221222
cex.getCause().printStackTrace();
222223
}
224+
225+
@Test
226+
public void messageCollection() {
227+
CompositeException compositeException = new CompositeException(Arrays.asList(ex1, ex3));
228+
assertEquals("2 exceptions occurred. ", compositeException.getMessage());
229+
}
230+
231+
@Test
232+
public void messageVarargs() {
233+
CompositeException compositeException = new CompositeException(ex1, ex2, ex3);
234+
assertEquals("3 exceptions occurred. ", compositeException.getMessage());
235+
}
223236
}

0 commit comments

Comments
 (0)