1515 */
1616package rx .exceptions ;
1717
18- import java .util .Collection ;
1918import java .util .HashSet ;
19+ import java .util .List ;
2020import java .util .Set ;
2121
2222import rx .annotations .Experimental ;
@@ -37,19 +37,6 @@ private Exceptions() {
3737 * value; {@code propagate} does not actually return anything
3838 */
3939 public static RuntimeException propagate (Throwable t ) {
40- return propagate (t , null );
41- }
42- /**
43- * Convenience method to throw a {@code RuntimeException} and {@code Error} directly
44- * or wrap any other exception type into a {@code RuntimeException} with an optional custom message.
45- * @param t the exception to throw directly or wrapped
46- * @param message the optional custom message to set up the RuntimeException thrown
47- * in case {@code t} is a checked exception.
48- * @return because {@code propagate} itself throws an exception or error, this is a sort of phantom return
49- * value; {@code propagate} does not actually return anything
50- */
51- @ Experimental
52- public static RuntimeException propagate (Throwable t , String message ) {
5340 /*
5441 * The return type of RuntimeException is a trick for code to be like this:
5542 *
@@ -63,10 +50,9 @@ public static RuntimeException propagate(Throwable t, String message) {
6350 } else if (t instanceof Error ) {
6451 throw (Error ) t ;
6552 } else {
66- throw new RuntimeException (message , t );
53+ throw new RuntimeException (t );
6754 }
6855 }
69-
7056 /**
7157 * Throws a particular {@code Throwable} only if it belongs to a set of "fatal" error varieties. These
7258 * varieties are as follows:
@@ -172,19 +158,24 @@ public static Throwable getFinalCause(Throwable e) {
172158 * @param exceptions the collection of exceptions. If null or empty, no exception is thrown.
173159 * If the collection contains a single exception, that exception is either thrown as-is or wrapped into a
174160 * CompositeException. Multiple exceptions are wrapped into a CompositeException.
175- * @param whileText the circumstance string to be appended to the thrown CompositeException, inserted after
176- * the sentences "Exception" and "Multiple exceptions".
177161 */
178162 @ Experimental
179- public static void throwIfAny (Collection <? extends Throwable > exceptions , String whileText ) {
163+ public static void throwIfAny (List <? extends Throwable > exceptions ) {
180164 if (exceptions != null && !exceptions .isEmpty ()) {
181165 if (exceptions .size () == 1 ) {
182- Throwable t = exceptions .iterator ().next ();
183- throw propagate (t , "Exception" + whileText );
184- } else {
185- throw new CompositeException (
186- "Multiple exceptions" + whileText , exceptions );
166+ Throwable t = exceptions .get (0 );
167+ // had to manually inline propagate because some tests attempt StackOverflowError
168+ // and can't handle it with the stack space remaining
169+ if (t instanceof RuntimeException ) {
170+ throw (RuntimeException ) t ;
171+ } else if (t instanceof Error ) {
172+ throw (Error ) t ;
173+ } else {
174+ throw new RuntimeException (t );
175+ }
187176 }
177+ throw new CompositeException (
178+ "Multiple exceptions" , exceptions );
188179 }
189180 }
190181}
0 commit comments