File tree Expand file tree Collapse file tree 2 files changed +29
-8
lines changed
main/java/io/reactivex/plugins
test/java/io/reactivex/plugins Expand file tree Collapse file tree 2 files changed +29
-8
lines changed Original file line number Diff line number Diff line change @@ -252,23 +252,22 @@ public static Scheduler onComputationScheduler(Scheduler defaultScheduler) {
252252 */
253253 public static void onError (Throwable error ) {
254254 Consumer <Throwable > f = errorHandler ;
255+
256+ if (error == null ) {
257+ error = new NullPointerException ("onError called with null. Null values are generally not allowed in 2.x operators and sources." );
258+ }
259+
255260 if (f != null ) {
256261 try {
257262 f .accept (error );
258263 return ;
259264 } catch (Throwable e ) {
260265 // Exceptions.throwIfFatal(e); TODO decide
261- if (error == null ) {
262- error = new NullPointerException ("onError called with null. Null values are generally not allowed in 2.x operators and sources." );
263- }
264266 e .printStackTrace (); // NOPMD
265267 uncaught (e );
266268 }
267- } else {
268- if (error == null ) {
269- error = new NullPointerException ("onError called with null. Null values are generally not allowed in 2.x operators and sources." );
270- }
271269 }
270+
272271 error .printStackTrace (); // NOPMD
273272 uncaught (error );
274273 }
Original file line number Diff line number Diff line change 1616
1717package io .reactivex .plugins ;
1818
19+ import java .util .concurrent .atomic .AtomicReference ;
1920import static org .junit .Assert .*;
2021
2122import java .io .IOException ;
@@ -1695,4 +1696,25 @@ public void onComplete() {
16951696 .assertComplete ();
16961697 }
16971698
1698- }
1699+ @ Test
1700+ public void onErrorNull () {
1701+ try {
1702+ final AtomicReference <Throwable > t = new AtomicReference <Throwable >();
1703+
1704+ RxJavaPlugins .setErrorHandler (new Consumer <Throwable >() {
1705+ @ Override
1706+ public void accept (final Throwable throwable ) throws Exception {
1707+ t .set (throwable );
1708+ }
1709+ });
1710+
1711+ RxJavaPlugins .onError (null );
1712+
1713+ final Throwable throwable = t .get ();
1714+ assertEquals ("onError called with null. Null values are generally not allowed in 2.x operators and sources." , throwable .getMessage ());
1715+ assertTrue (throwable instanceof NullPointerException );
1716+ } finally {
1717+ RxJavaPlugins .reset ();
1718+ }
1719+ }
1720+ }
You can’t perform that action at this time.
0 commit comments