Skip to content

Commit 0d4b610

Browse files
akarnokdakarnokd
akarnokd
authored and
akarnokd
committed
Reporting stackoverflow caused stackoverflow
1 parent 4b4bea2 commit 0d4b610

File tree

9 files changed

+23
-32
lines changed

9 files changed

+23
-32
lines changed

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

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
package rx.exceptions;
1717

18-
import java.util.Collection;
1918
import java.util.HashSet;
19+
import java.util.List;
2020
import java.util.Set;
2121

2222
import 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
}

src/main/java/rx/internal/operators/OperatorPublish.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public void onError(Throwable e) {
163163
errors.add(e2);
164164
}
165165
}
166-
Exceptions.throwIfAny(errors, " while emitting onError");
166+
Exceptions.throwIfAny(errors);
167167
}
168168

169169
@Override

src/main/java/rx/internal/util/SubscriptionList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private static void unsubscribeFromAll(Collection<Subscription> subscriptions) {
106106
es.add(e);
107107
}
108108
}
109-
Exceptions.throwIfAny(es, " while unsubscribing.");
109+
Exceptions.throwIfAny(es);
110110
}
111111
/* perf support */
112112
public void clear() {

src/main/java/rx/internal/util/SubscriptionRandomList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,6 @@ private static <T extends Subscription> void unsubscribeFromAll(Collection<T> su
155155
es.add(e);
156156
}
157157
}
158-
Exceptions.throwIfAny(es, " while unsubscribing.");
158+
Exceptions.throwIfAny(es);
159159
}
160160
}

src/main/java/rx/subjects/AsyncSubject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void onError(final Throwable e) {
120120
}
121121
}
122122

123-
Exceptions.throwIfAny(errors, " while emitting AsyncSubject.onError");
123+
Exceptions.throwIfAny(errors);
124124
}
125125
}
126126

src/main/java/rx/subjects/BehaviorSubject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public void onError(Throwable e) {
146146
}
147147
}
148148

149-
Exceptions.throwIfAny(errors, " while emitting BehaviorSubject.onError");
149+
Exceptions.throwIfAny(errors);
150150
}
151151
}
152152

src/main/java/rx/subjects/PublishSubject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void onError(final Throwable e) {
104104
errors.add(e2);
105105
}
106106
}
107-
Exceptions.throwIfAny(errors, " while emitting PublishSubject.onError");
107+
Exceptions.throwIfAny(errors);
108108
}
109109
}
110110

src/main/java/rx/subjects/ReplaySubject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ public void onError(final Throwable e) {
391391
}
392392
}
393393

394-
Exceptions.throwIfAny(errors, " while emitting ReplaySubject.onError");
394+
Exceptions.throwIfAny(errors);
395395
}
396396
}
397397

src/main/java/rx/subscriptions/CompositeSubscription.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,6 @@ private static void unsubscribeFromAll(Collection<Subscription> subscriptions) {
141141
es.add(e);
142142
}
143143
}
144-
Exceptions.throwIfAny(es, " while unsubscribing.");
144+
Exceptions.throwIfAny(es);
145145
}
146146
}

0 commit comments

Comments
 (0)