Skip to content

1.x: Deprecate CompositeException constructor with message prefix #3762

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

Merged
merged 1 commit into from
Mar 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/rx/exceptions/CompositeException.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public final class CompositeException extends RuntimeException {
private final List<Throwable> exceptions;
private final String message;

/** @deprecated please use {@link #CompositeException(Collection)} */
@Deprecated
public CompositeException(String messagePrefix, Collection<? extends Throwable> errors) {
Set<Throwable> deDupedExceptions = new LinkedHashSet<Throwable>();
List<Throwable> _exceptions = new ArrayList<Throwable>();
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/rx/exceptions/Exceptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ public static void throwIfAny(List<? extends Throwable> exceptions) {
throw new RuntimeException(t);
}
}
throw new CompositeException(
"Multiple exceptions", exceptions);
throw new CompositeException(exceptions);
}
}

Expand Down
17 changes: 15 additions & 2 deletions src/test/java/rx/exceptions/CompositeExceptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.junit.Test;
Expand Down Expand Up @@ -50,7 +51,7 @@ public void testMultipleWithSameCause() {
Throwable e1 = new Throwable("1", rootCause);
Throwable e2 = new Throwable("2", rootCause);
Throwable e3 = new Throwable("3", rootCause);
CompositeException ce = new CompositeException("3 failures with same root cause", Arrays.asList(e1, e2, e3));
CompositeException ce = new CompositeException(Arrays.asList(e1, e2, e3));

System.err.println("----------------------------- print composite stacktrace");
ce.printStackTrace();
Expand Down Expand Up @@ -174,7 +175,7 @@ public void testNullCollection() {
}
@Test
public void testNullElement() {
CompositeException composite = new CompositeException(Arrays.asList((Throwable)null));
CompositeException composite = new CompositeException(Collections.singletonList((Throwable) null));
composite.getCause();
composite.printStackTrace();
}
Expand Down Expand Up @@ -220,4 +221,16 @@ public synchronized Throwable initCause(Throwable cause) {
System.err.println("----------------------------- print cause stacktrace");
cex.getCause().printStackTrace();
}

@Test
public void messageCollection() {
CompositeException compositeException = new CompositeException(Arrays.asList(ex1, ex3));
assertEquals("2 exceptions occurred. ", compositeException.getMessage());
}

@Test
public void messageVarargs() {
CompositeException compositeException = new CompositeException(ex1, ex2, ex3);
assertEquals("3 exceptions occurred. ", compositeException.getMessage());
}
}