Skip to content

Commit 9b08870

Browse files
dlewzsxwing
authored andcommitted
throwIfFatal() now throws OnCompletedFailedException (#3886)
Otherwise, if there's an error in onCompleted, the exception is swallowed and unreported.
1 parent 7b11b1c commit 9b08870

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public static RuntimeException propagate(Throwable t) {
6161
* <ul>
6262
* <li>{@link OnErrorNotImplementedException}</li>
6363
* <li>{@link OnErrorFailedException}</li>
64+
* <li>{@link OnCompletedFailedException}</li>
6465
* <li>{@code StackOverflowError}</li>
6566
* <li>{@code VirtualMachineError}</li>
6667
* <li>{@code ThreadDeath}</li>
@@ -80,6 +81,8 @@ public static void throwIfFatal(Throwable t) {
8081
throw (OnErrorNotImplementedException) t;
8182
} else if (t instanceof OnErrorFailedException) {
8283
throw (OnErrorFailedException) t;
84+
} else if (t instanceof OnCompletedFailedException) {
85+
throw (OnCompletedFailedException) t;
8386
}
8487
// values here derived from https://github.com/ReactiveX/RxJava/issues/748#issuecomment-32471495
8588
else if (t instanceof StackOverflowError) {

src/test/java/rx/exceptions/ExceptionsTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,28 @@ public void call(Integer t1) {
4646
});
4747
}
4848

49+
/**
50+
* https://github.com/ReactiveX/RxJava/issues/3885
51+
*/
52+
@Test(expected = OnCompletedFailedException.class)
53+
public void testOnCompletedExceptionIsThrown() {
54+
Observable.empty()
55+
.subscribe(new Subscriber<Object>() {
56+
@Override
57+
public void onCompleted() {
58+
throw new RuntimeException();
59+
}
60+
61+
@Override
62+
public void onError(Throwable e) {
63+
}
64+
65+
@Override
66+
public void onNext(Object o) {
67+
}
68+
});
69+
}
70+
4971
@Test
5072
public void testStackOverflowWouldOccur() {
5173
final PublishSubject<Integer> a = PublishSubject.create();

0 commit comments

Comments
 (0)