File tree 2 files changed +29
-8
lines changed
main/java/io/reactivex/plugins
test/java/io/reactivex/plugins
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) {
252
252
*/
253
253
public static void onError (Throwable error ) {
254
254
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
+
255
260
if (f != null ) {
256
261
try {
257
262
f .accept (error );
258
263
return ;
259
264
} catch (Throwable e ) {
260
265
// 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
- }
264
266
e .printStackTrace (); // NOPMD
265
267
uncaught (e );
266
268
}
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
- }
271
269
}
270
+
272
271
error .printStackTrace (); // NOPMD
273
272
uncaught (error );
274
273
}
Original file line number Diff line number Diff line change 16
16
17
17
package io .reactivex .plugins ;
18
18
19
+ import java .util .concurrent .atomic .AtomicReference ;
19
20
import static org .junit .Assert .*;
20
21
21
22
import java .io .IOException ;
@@ -1695,4 +1696,25 @@ public void onComplete() {
1695
1696
.assertComplete ();
1696
1697
}
1697
1698
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