Skip to content

Commit 5b8845d

Browse files
JakeWhartonakarnokd
authored andcommitted
Avoid potential NPE when onError throws. (#4398)
t2 was only initialized if canceling threw an exception. In the happy path it would have never been initialized so when onError threw the call to suppress() would NPE.
1 parent e1cec33 commit 5b8845d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/main/java/io/reactivex/subscribers/SafeSubscriber.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,11 @@ public void onError(Throwable t) {
154154
}
155155
} catch (Throwable e) {
156156
Exceptions.throwIfFatal(e);
157-
t2.suppress(e);
158-
157+
if (t2 == null) {
158+
t2 = new CompositeException(t, e);
159+
} else {
160+
t2.suppress(e);
161+
}
159162
RxJavaPlugins.onError(t2);
160163
}
161164
}

0 commit comments

Comments
 (0)