Skip to content

Commit

Permalink
2.x: Enhance NPE messages (#4593)
Browse files Browse the repository at this point in the history
  • Loading branch information
vanniktech authored and akarnokd committed Sep 23, 2016
1 parent 603f6c6 commit 4f86ee0
Show file tree
Hide file tree
Showing 24 changed files with 40 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.<Object>createOnNext(t));
Expand Down Expand Up @@ -71,4 +71,4 @@ public void onComplete() {
RxJavaPlugins.onError(ex);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void subscribeActual(Subscriber<? super T> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ public void subscribe(Subscriber<? super T> 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);
Expand Down Expand Up @@ -659,4 +659,4 @@ public void clear() {
queue.clear();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected void subscribeActual(MaybeObserver<? super T> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void subscribeActual(Observer<? super T> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public void subscribe(Observer<? super T> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected void subscribeActual(SingleObserver<? super T> 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);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/reactivex/observers/SafeObserver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/reactivex/plugins/RxJavaPlugins.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/reactivex/processors/AsyncProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> as : subscribers.getAndSet(TERMINATED)) {
as.onError(ex);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/reactivex/processors/BehaviorProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/reactivex/processors/PublishProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> s : subscribers.get()) {
Expand All @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/reactivex/processors/ReplayProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -1230,4 +1230,4 @@ public int size() {
return s;
}
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/io/reactivex/subjects/AsyncSubject.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> as : subscribers.getAndSet(TERMINATED)) {
as.onError(ex);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/reactivex/subjects/BehaviorSubject.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/reactivex/subjects/PublishSubject.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> s : subscribers.get()) {
Expand All @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/reactivex/subjects/ReplaySubject.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/reactivex/subscribers/SafeSubscriber.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4f86ee0

Please sign in to comment.