Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/main/java/io/reactivex/plugins/RxJavaPlugins.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,23 +252,22 @@ public static Scheduler onComputationScheduler(Scheduler defaultScheduler) {
*/
public static void onError(Throwable error) {
Consumer<Throwable> f = errorHandler;

if (error == null) {
error = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
}

if (f != null) {
try {
f.accept(error);
return;
} catch (Throwable e) {
// Exceptions.throwIfFatal(e); TODO decide
if (error == null) {
error = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
}
e.printStackTrace(); // NOPMD
uncaught(e);
}
} else {
if (error == null) {
error = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
}
}

error.printStackTrace(); // NOPMD
uncaught(error);
}
Expand Down
24 changes: 23 additions & 1 deletion src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.reactivex.plugins;

import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.*;

import java.io.IOException;
Expand Down Expand Up @@ -1695,4 +1696,25 @@ public void onComplete() {
.assertComplete();
}

}
@Test
public void onErrorNull() {
try {
final AtomicReference<Throwable> t = new AtomicReference<Throwable>();

RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
@Override
public void accept(final Throwable throwable) throws Exception {
t.set(throwable);
}
});

RxJavaPlugins.onError(null);

final Throwable throwable = t.get();
assertEquals("onError called with null. Null values are generally not allowed in 2.x operators and sources.", throwable.getMessage());
assertTrue(throwable instanceof NullPointerException);
} finally {
RxJavaPlugins.reset();
}
}
}