From 68844946d1152a8a3fde2ab7cddd529622ba65d1 Mon Sep 17 00:00:00 2001 From: Niklas Baudy Date: Fri, 23 Sep 2016 23:56:42 +0200 Subject: [PATCH] 2.x: Enhance NPE messages --- .../internal/observers/ToNotificationObserver.java | 4 ++-- .../internal/operators/flowable/FlowableError.java | 2 +- .../internal/operators/flowable/FlowableGenerate.java | 4 ++-- .../internal/operators/flowable/FlowableGroupBy.java | 4 ++-- .../internal/operators/maybe/MaybeErrorCallable.java | 2 +- .../internal/operators/observable/ObservableBuffer.java | 2 +- .../internal/operators/observable/ObservableError.java | 2 +- .../internal/operators/observable/ObservableGenerate.java | 4 ++-- .../internal/operators/observable/ObservableGroupBy.java | 2 +- .../internal/operators/observable/ObservableZip.java | 2 +- .../io/reactivex/internal/operators/single/SingleError.java | 2 +- src/main/java/io/reactivex/observers/SafeObserver.java | 4 ++-- .../java/io/reactivex/observers/SerializedObserver.java | 2 +- src/main/java/io/reactivex/plugins/RxJavaPlugins.java | 4 ++-- src/main/java/io/reactivex/processors/AsyncProcessor.java | 4 ++-- .../java/io/reactivex/processors/BehaviorProcessor.java | 4 ++-- src/main/java/io/reactivex/processors/PublishProcessor.java | 4 ++-- src/main/java/io/reactivex/processors/ReplayProcessor.java | 6 +++--- src/main/java/io/reactivex/subjects/AsyncSubject.java | 4 ++-- src/main/java/io/reactivex/subjects/BehaviorSubject.java | 4 ++-- src/main/java/io/reactivex/subjects/PublishSubject.java | 4 ++-- src/main/java/io/reactivex/subjects/ReplaySubject.java | 4 ++-- src/main/java/io/reactivex/subjects/UnicastSubject.java | 4 ++-- src/main/java/io/reactivex/subscribers/SafeSubscriber.java | 4 ++-- .../java/io/reactivex/subscribers/SerializedSubscriber.java | 2 +- 25 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/main/java/io/reactivex/internal/observers/ToNotificationObserver.java b/src/main/java/io/reactivex/internal/observers/ToNotificationObserver.java index c20de78418..f1cac318d8 100644 --- a/src/main/java/io/reactivex/internal/observers/ToNotificationObserver.java +++ b/src/main/java/io/reactivex/internal/observers/ToNotificationObserver.java @@ -40,7 +40,7 @@ public void onSubscribe(Disposable s) { public void onNext(T t) { if (t == null) { s.dispose(); - onError(new NullPointerException()); + onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources.")); } else { try { consumer.accept(Notification.createOnNext(t)); @@ -71,4 +71,4 @@ public void onComplete() { RxJavaPlugins.onError(ex); } } -} \ No newline at end of file +} diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableError.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableError.java index eba929678b..4ce527a649 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableError.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableError.java @@ -36,7 +36,7 @@ public void subscribeActual(Subscriber s) { error = t; } if (error == null) { - error = new NullPointerException(); + error = new NullPointerException("Callable returned null throwable. Null values are generally not allowed in 2.x operators and sources."); } EmptySubscription.error(error, s); } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableGenerate.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableGenerate.java index d7ea104fbf..b8da2c0cd9 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableGenerate.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableGenerate.java @@ -174,7 +174,7 @@ public void cancel() { @Override public void onNext(T t) { if (t == null) { - onError(new NullPointerException()); + onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources.")); return; } actual.onNext(t); @@ -183,7 +183,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (t == null) { - t = new NullPointerException(); + t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources."); } terminate = true; actual.onError(t); diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java index 0c8855deb7..909ee5943b 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableGroupBy.java @@ -462,7 +462,7 @@ public void subscribe(Subscriber s) { public void onNext(T t) { if (t == null) { - error = new NullPointerException(); + error = new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."); done = true; } else { queue.offer(t); @@ -659,4 +659,4 @@ public void clear() { queue.clear(); } } -} \ No newline at end of file +} diff --git a/src/main/java/io/reactivex/internal/operators/maybe/MaybeErrorCallable.java b/src/main/java/io/reactivex/internal/operators/maybe/MaybeErrorCallable.java index 65b9597fa7..d913b4ffb6 100644 --- a/src/main/java/io/reactivex/internal/operators/maybe/MaybeErrorCallable.java +++ b/src/main/java/io/reactivex/internal/operators/maybe/MaybeErrorCallable.java @@ -45,7 +45,7 @@ protected void subscribeActual(MaybeObserver observer) { } if (ex == null) { - ex = new NullPointerException(); + ex = new NullPointerException("Callable returned null throwable. Null values are generally not allowed in 2.x operators and sources."); } observer.onError(ex); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableBuffer.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableBuffer.java index 4c089dad77..26c64a76db 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableBuffer.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableBuffer.java @@ -205,7 +205,7 @@ public void onNext(T t) { if (b == null) { buffers.clear(); s.dispose(); - actual.onError(new NullPointerException()); + actual.onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources.")); return; } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableError.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableError.java index 5b6df33fa3..6123e285fc 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableError.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableError.java @@ -34,7 +34,7 @@ public void subscribeActual(Observer s) { error = t; } if (error == null) { - error = new NullPointerException(); + error = new NullPointerException("Callable returned null throwable. Null values are generally not allowed in 2.x operators and sources."); } EmptyDisposable.error(error, s); } diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableGenerate.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableGenerate.java index f45da9e028..f5bcc6516d 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableGenerate.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableGenerate.java @@ -134,7 +134,7 @@ public boolean isDisposed() { @Override public void onNext(T t) { if (t == null) { - onError(new NullPointerException()); + onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources.")); return; } actual.onNext(t); @@ -143,7 +143,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (t == null) { - t = new NullPointerException(); + t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources."); } terminate = true; actual.onError(t); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupBy.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupBy.java index db1c512c3d..83aeb7f2d4 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupBy.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableGroupBy.java @@ -260,7 +260,7 @@ public void subscribe(Observer s) { public void onNext(T t) { if (t == null) { - error = new NullPointerException(); + error = new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."); done = true; } else { queue.offer(t); diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java b/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java index 784e45d427..43e5e8c549 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservableZip.java @@ -268,7 +268,7 @@ public void onSubscribe(Disposable s) { public void onNext(T t) { if (t == null) { s.get().dispose(); - onError(new NullPointerException()); + onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources.")); return; } if (!queue.offer(t)) { diff --git a/src/main/java/io/reactivex/internal/operators/single/SingleError.java b/src/main/java/io/reactivex/internal/operators/single/SingleError.java index b6e445cf88..8c784299ce 100644 --- a/src/main/java/io/reactivex/internal/operators/single/SingleError.java +++ b/src/main/java/io/reactivex/internal/operators/single/SingleError.java @@ -39,7 +39,7 @@ protected void subscribeActual(SingleObserver s) { } if (error == null) { - error = new NullPointerException(); + error = new NullPointerException("Callable returned null throwable. Null values are generally not allowed in 2.x operators and sources."); } EmptyDisposable.error(error, s); diff --git a/src/main/java/io/reactivex/observers/SafeObserver.java b/src/main/java/io/reactivex/observers/SafeObserver.java index 592b1f5e79..015cbe0c81 100644 --- a/src/main/java/io/reactivex/observers/SafeObserver.java +++ b/src/main/java/io/reactivex/observers/SafeObserver.java @@ -84,7 +84,7 @@ public void onNext(T t) { } if (t == null) { - Throwable ex = new NullPointerException(); + Throwable ex = new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."); try { s.dispose(); } catch (Throwable e1) { @@ -167,7 +167,7 @@ public void onError(Throwable t) { } if (t == null) { - t = new NullPointerException(); + t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources."); } try { diff --git a/src/main/java/io/reactivex/observers/SerializedObserver.java b/src/main/java/io/reactivex/observers/SerializedObserver.java index 5d394c07e0..04a353b072 100644 --- a/src/main/java/io/reactivex/observers/SerializedObserver.java +++ b/src/main/java/io/reactivex/observers/SerializedObserver.java @@ -89,7 +89,7 @@ public void onNext(T t) { } if (t == null) { s.dispose(); - onError(new NullPointerException()); + onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources.")); return; } synchronized (this) { diff --git a/src/main/java/io/reactivex/plugins/RxJavaPlugins.java b/src/main/java/io/reactivex/plugins/RxJavaPlugins.java index 083efb1426..8a956bd8aa 100644 --- a/src/main/java/io/reactivex/plugins/RxJavaPlugins.java +++ b/src/main/java/io/reactivex/plugins/RxJavaPlugins.java @@ -259,14 +259,14 @@ public static void onError(Throwable error) { } catch (Throwable e) { // Exceptions.throwIfFatal(e); TODO decide if (error == null) { - error = new NullPointerException(); + 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(); + error = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources."); } } error.printStackTrace(); // NOPMD diff --git a/src/main/java/io/reactivex/processors/AsyncProcessor.java b/src/main/java/io/reactivex/processors/AsyncProcessor.java index b311a20cc3..3ab4fcf44e 100644 --- a/src/main/java/io/reactivex/processors/AsyncProcessor.java +++ b/src/main/java/io/reactivex/processors/AsyncProcessor.java @@ -87,7 +87,7 @@ public void onNext(T t) { @SuppressWarnings("unchecked") void nullOnNext() { value = null; - Throwable ex = new NullPointerException(); + Throwable ex = new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."); error = ex; for (AsyncSubscription as : subscribers.getAndSet(TERMINATED)) { as.onError(ex); @@ -98,7 +98,7 @@ void nullOnNext() { @Override public void onError(Throwable t) { if (t == null) { - t = new NullPointerException(); + t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources."); } if (subscribers.get() == TERMINATED) { RxJavaPlugins.onError(t); diff --git a/src/main/java/io/reactivex/processors/BehaviorProcessor.java b/src/main/java/io/reactivex/processors/BehaviorProcessor.java index 9fe5f5d5e3..f39b14e325 100644 --- a/src/main/java/io/reactivex/processors/BehaviorProcessor.java +++ b/src/main/java/io/reactivex/processors/BehaviorProcessor.java @@ -175,7 +175,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (t == null) { - onError(new NullPointerException()); + onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources.")); return; } if (done) { @@ -191,7 +191,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (t == null) { - t = new NullPointerException(); + t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources."); } if (done) { RxJavaPlugins.onError(t); diff --git a/src/main/java/io/reactivex/processors/PublishProcessor.java b/src/main/java/io/reactivex/processors/PublishProcessor.java index 3d4ca4305f..6605bf9150 100644 --- a/src/main/java/io/reactivex/processors/PublishProcessor.java +++ b/src/main/java/io/reactivex/processors/PublishProcessor.java @@ -189,7 +189,7 @@ public void onNext(T t) { return; } if (t == null) { - onError(new NullPointerException()); + onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources.")); return; } for (PublishSubscription s : subscribers.get()) { @@ -205,7 +205,7 @@ public void onError(Throwable t) { return; } if (t == null) { - t = new NullPointerException(); + t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources."); } error = t; diff --git a/src/main/java/io/reactivex/processors/ReplayProcessor.java b/src/main/java/io/reactivex/processors/ReplayProcessor.java index 9212221407..157c66babc 100644 --- a/src/main/java/io/reactivex/processors/ReplayProcessor.java +++ b/src/main/java/io/reactivex/processors/ReplayProcessor.java @@ -265,7 +265,7 @@ public void onSubscribe(Subscription s) { @Override public void onNext(T t) { if (t == null) { - onError(new NullPointerException()); + onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources.")); return; } if (done) { @@ -283,7 +283,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (t == null) { - t = new NullPointerException(); + t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources."); } if (done) { RxJavaPlugins.onError(t); @@ -1230,4 +1230,4 @@ public int size() { return s; } } -} \ No newline at end of file +} diff --git a/src/main/java/io/reactivex/subjects/AsyncSubject.java b/src/main/java/io/reactivex/subjects/AsyncSubject.java index b712717204..7c013f7b72 100644 --- a/src/main/java/io/reactivex/subjects/AsyncSubject.java +++ b/src/main/java/io/reactivex/subjects/AsyncSubject.java @@ -86,7 +86,7 @@ public void onNext(T t) { @SuppressWarnings("unchecked") void nullOnNext() { value = null; - Throwable ex = new NullPointerException(); + Throwable ex = new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."); error = ex; for (AsyncDisposable as : subscribers.getAndSet(TERMINATED)) { as.onError(ex); @@ -97,7 +97,7 @@ void nullOnNext() { @Override public void onError(Throwable t) { if (t == null) { - t = new NullPointerException(); + t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources."); } if (subscribers.get() == TERMINATED) { RxJavaPlugins.onError(t); diff --git a/src/main/java/io/reactivex/subjects/BehaviorSubject.java b/src/main/java/io/reactivex/subjects/BehaviorSubject.java index 41f73a881e..4fad1df192 100644 --- a/src/main/java/io/reactivex/subjects/BehaviorSubject.java +++ b/src/main/java/io/reactivex/subjects/BehaviorSubject.java @@ -172,7 +172,7 @@ public void onSubscribe(Disposable s) { @Override public void onNext(T t) { if (t == null) { - onError(new NullPointerException()); + onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources.")); return; } if (done) { @@ -188,7 +188,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (t == null) { - t = new NullPointerException(); + t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources."); } if (done) { RxJavaPlugins.onError(t); diff --git a/src/main/java/io/reactivex/subjects/PublishSubject.java b/src/main/java/io/reactivex/subjects/PublishSubject.java index e4a5409795..32dfe7b195 100644 --- a/src/main/java/io/reactivex/subjects/PublishSubject.java +++ b/src/main/java/io/reactivex/subjects/PublishSubject.java @@ -175,7 +175,7 @@ public void onNext(T t) { return; } if (t == null) { - onError(new NullPointerException("Subject got a null value. Null values are generally not allowed in 2.x operators and sources.")); + onError(new NullPointerException("onNext got a null value. Null values are generally not allowed in 2.x operators and sources.")); return; } for (PublishDisposable s : subscribers.get()) { @@ -191,7 +191,7 @@ public void onError(Throwable t) { return; } if (t == null) { - t = new NullPointerException(); + t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources."); } error = t; diff --git a/src/main/java/io/reactivex/subjects/ReplaySubject.java b/src/main/java/io/reactivex/subjects/ReplaySubject.java index 835819ba9f..df27bd37cd 100644 --- a/src/main/java/io/reactivex/subjects/ReplaySubject.java +++ b/src/main/java/io/reactivex/subjects/ReplaySubject.java @@ -248,7 +248,7 @@ public void onSubscribe(Disposable s) { @Override public void onNext(T t) { if (t == null) { - onError(new NullPointerException()); + onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources.")); return; } if (done) { @@ -266,7 +266,7 @@ public void onNext(T t) { @Override public void onError(Throwable t) { if (t == null) { - t = new NullPointerException(); + t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources."); } if (done) { RxJavaPlugins.onError(t); diff --git a/src/main/java/io/reactivex/subjects/UnicastSubject.java b/src/main/java/io/reactivex/subjects/UnicastSubject.java index f5570772bb..ef67d907a1 100644 --- a/src/main/java/io/reactivex/subjects/UnicastSubject.java +++ b/src/main/java/io/reactivex/subjects/UnicastSubject.java @@ -184,7 +184,7 @@ public void onNext(T t) { return; } if (t == null) { - onError(new NullPointerException()); + onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources.")); return; } queue.offer(t); @@ -198,7 +198,7 @@ public void onError(Throwable t) { return; } if (t == null) { - t = new NullPointerException(); + t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources."); } error = t; done = true; diff --git a/src/main/java/io/reactivex/subscribers/SafeSubscriber.java b/src/main/java/io/reactivex/subscribers/SafeSubscriber.java index a08e39a911..a7bcd64c0f 100644 --- a/src/main/java/io/reactivex/subscribers/SafeSubscriber.java +++ b/src/main/java/io/reactivex/subscribers/SafeSubscriber.java @@ -73,7 +73,7 @@ public void onNext(T t) { } if (t == null) { - Throwable ex = new NullPointerException(); + Throwable ex = new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."); try { s.cancel(); } catch (Throwable e1) { @@ -155,7 +155,7 @@ public void onError(Throwable t) { } if (t == null) { - t = new NullPointerException(); + t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources."); } try { diff --git a/src/main/java/io/reactivex/subscribers/SerializedSubscriber.java b/src/main/java/io/reactivex/subscribers/SerializedSubscriber.java index 1ac4a82cd6..022e5f0c77 100644 --- a/src/main/java/io/reactivex/subscribers/SerializedSubscriber.java +++ b/src/main/java/io/reactivex/subscribers/SerializedSubscriber.java @@ -76,7 +76,7 @@ public void onNext(T t) { } if (t == null) { subscription.cancel(); - onError(new NullPointerException()); + onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources.")); return; } synchronized (this) {