Skip to content

Commit 679cdf6

Browse files
vanniktechakarnokd
authored andcommitted
2.x: Enhance NPE message in Create functions of all Base Reactive Types (#4561)
1 parent f4daec6 commit 679cdf6

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

src/main/java/io/reactivex/internal/operators/completable/CompletableCreate.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void onComplete() {
7474
@Override
7575
public void onError(Throwable t) {
7676
if (t == null) {
77-
t = new NullPointerException();
77+
t = new NullPointerException("Emitter got a null throwable. Null values are generally not allowed in 2.x operators and sources.");
7878
}
7979
if (get() != DisposableHelper.DISPOSED) {
8080
Disposable d = getAndSet(DisposableHelper.DISPOSED);

src/main/java/io/reactivex/internal/operators/flowable/FlowableCreate.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void onNext(T t) {
107107
return;
108108
}
109109
if (t == null) {
110-
onError(new NullPointerException("t is null"));
110+
onError(new NullPointerException("Emitter got a null value. Null values are generally not allowed in 2.x operators and sources."));
111111
return;
112112
}
113113
if (get() == 0 && compareAndSet(0, 1)) {
@@ -134,7 +134,7 @@ public void onError(Throwable t) {
134134
return;
135135
}
136136
if (t == null) {
137-
t = new NullPointerException("t is null");
137+
t = new NullPointerException("Emitter got a null throwable. Null values are generally not allowed in 2.x operators and sources.");
138138
}
139139
if (error.addThrowable(t)) {
140140
done = true;

src/main/java/io/reactivex/internal/operators/maybe/MaybeCreate.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void onSuccess(T value) {
6969
if (d != DisposableHelper.DISPOSED) {
7070
try {
7171
if (value == null) {
72-
actual.onError(new NullPointerException());
72+
actual.onError(new NullPointerException("Emitter got a null value. Null values are generally not allowed in 2.x operators and sources."));
7373
} else {
7474
actual.onSuccess(value);
7575
}
@@ -85,7 +85,7 @@ public void onSuccess(T value) {
8585
@Override
8686
public void onError(Throwable t) {
8787
if (t == null) {
88-
t = new NullPointerException();
88+
t = new NullPointerException("Emitter got a null throwable. Null values are generally not allowed in 2.x operators and sources.");
8989
}
9090
if (get() != DisposableHelper.DISPOSED) {
9191
Disposable d = getAndSet(DisposableHelper.DISPOSED);

src/main/java/io/reactivex/internal/operators/observable/ObservableCreate.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static final class CreateEmitter<T>
6060
@Override
6161
public void onNext(T t) {
6262
if (t == null) {
63-
onError(new NullPointerException());
63+
onError(new NullPointerException("Emitter got a null value. Null values are generally not allowed in 2.x operators and sources."));
6464
}
6565
if (!isDisposed()) {
6666
observer.onNext(t);
@@ -70,7 +70,7 @@ public void onNext(T t) {
7070
@Override
7171
public void onError(Throwable t) {
7272
if (t == null) {
73-
t = new NullPointerException();
73+
t = new NullPointerException("Emitter got a null throwable. Null values are generally not allowed in 2.x operators and sources.");
7474
}
7575
if (!isDisposed()) {
7676
try {

src/main/java/io/reactivex/internal/operators/single/SingleCreate.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void onSuccess(T value) {
6363
if (d != DisposableHelper.DISPOSED) {
6464
try {
6565
if (value == null) {
66-
actual.onError(new NullPointerException());
66+
actual.onError(new NullPointerException("Emitter got a null value. Null values are generally not allowed in 2.x operators and sources."));
6767
} else {
6868
actual.onSuccess(value);
6969
}
@@ -79,7 +79,7 @@ public void onSuccess(T value) {
7979
@Override
8080
public void onError(Throwable t) {
8181
if (t == null) {
82-
t = new NullPointerException();
82+
t = new NullPointerException("Emitter got a null throwable. Null values are generally not allowed in 2.x operators and sources.");
8383
}
8484
if (get() != DisposableHelper.DISPOSED) {
8585
Disposable d = getAndSet(DisposableHelper.DISPOSED);

0 commit comments

Comments
 (0)