Skip to content

Commit 24448b4

Browse files
authored
2.x fix Flowable.create() not reporting null values properly, unify (#4583)
exception msg across
1 parent 6e99ad0 commit 24448b4

File tree

7 files changed

+339
-14
lines changed

7 files changed

+339
-14
lines changed

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

Lines changed: 1 addition & 1 deletion
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("Emitter got a null throwable. Null values are generally not allowed in 2.x operators and sources.");
77+
t = new NullPointerException("onError called with null. 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

Lines changed: 46 additions & 3 deletions
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("Emitter got a null value. Null values are generally not allowed in 2.x operators and sources."));
110+
onError(new NullPointerException("onNext called with null. 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("Emitter got a null throwable. Null values are generally not allowed in 2.x operators and sources.");
137+
t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
138138
}
139139
if (error.addThrowable(t)) {
140140
done = true;
@@ -265,6 +265,7 @@ public void onComplete() {
265265
@Override
266266
public void onError(Throwable e) {
267267
if (isCancelled()) {
268+
RxJavaPlugins.onError(e);
268269
return;
269270
}
270271
try {
@@ -337,7 +338,12 @@ public void onNext(T t) {
337338
return;
338339
}
339340

340-
actual.onNext(t);
341+
if (t != null) {
342+
actual.onNext(t);
343+
} else {
344+
onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."));
345+
return;
346+
}
341347

342348
for (;;) {
343349
long r = get();
@@ -363,6 +369,11 @@ public final void onNext(T t) {
363369
return;
364370
}
365371

372+
if (t == null) {
373+
onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."));
374+
return;
375+
}
376+
366377
if (get() != 0) {
367378
actual.onNext(t);
368379
BackpressureHelper.produced(this, 1);
@@ -426,12 +437,29 @@ static final class BufferAsyncEmitter<T> extends BaseEmitter<T> {
426437

427438
@Override
428439
public void onNext(T t) {
440+
if (done || isCancelled()) {
441+
return;
442+
}
443+
444+
if (t == null) {
445+
onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."));
446+
return;
447+
}
429448
queue.offer(t);
430449
drain();
431450
}
432451

433452
@Override
434453
public void onError(Throwable e) {
454+
if (done || isCancelled()) {
455+
RxJavaPlugins.onError(e);
456+
return;
457+
}
458+
459+
if (e == null) {
460+
e = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
461+
}
462+
435463
error = e;
436464
done = true;
437465
drain();
@@ -552,12 +580,27 @@ static final class LatestAsyncEmitter<T> extends BaseEmitter<T> {
552580

553581
@Override
554582
public void onNext(T t) {
583+
if (done || isCancelled()) {
584+
return;
585+
}
586+
587+
if (t == null) {
588+
onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."));
589+
return;
590+
}
555591
queue.set(t);
556592
drain();
557593
}
558594

559595
@Override
560596
public void onError(Throwable e) {
597+
if (done || isCancelled()) {
598+
RxJavaPlugins.onError(e);
599+
return;
600+
}
601+
if (e == null) {
602+
onError(new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources."));
603+
}
561604
error = e;
562605
done = true;
563606
drain();

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

Lines changed: 2 additions & 2 deletions
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("Emitter got a null value. Null values are generally not allowed in 2.x operators and sources."));
72+
actual.onError(new NullPointerException("onSuccess called with null. 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("Emitter got a null throwable. Null values are generally not allowed in 2.x operators and sources.");
88+
t = new NullPointerException("onError called with null. 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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ static final class CreateEmitter<T>
6060
@Override
6161
public void onNext(T t) {
6262
if (t == null) {
63-
onError(new NullPointerException("Emitter got a null value. Null values are generally not allowed in 2.x operators and sources."));
63+
onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."));
64+
return;
6465
}
6566
if (!isDisposed()) {
6667
observer.onNext(t);
@@ -70,7 +71,7 @@ public void onNext(T t) {
7071
@Override
7172
public void onError(Throwable t) {
7273
if (t == null) {
73-
t = new NullPointerException("Emitter got a null throwable. Null values are generally not allowed in 2.x operators and sources.");
74+
t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
7475
}
7576
if (!isDisposed()) {
7677
try {
@@ -151,7 +152,7 @@ public void onNext(T t) {
151152
return;
152153
}
153154
if (t == null) {
154-
onError(new NullPointerException("t is null"));
155+
onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."));
155156
return;
156157
}
157158
if (get() == 0 && compareAndSet(0, 1)) {
@@ -178,7 +179,7 @@ public void onError(Throwable t) {
178179
return;
179180
}
180181
if (t == null) {
181-
t = new NullPointerException("t is null");
182+
t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
182183
}
183184
if (error.addThrowable(t)) {
184185
done = true;

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

Lines changed: 2 additions & 2 deletions
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("Emitter got a null value. Null values are generally not allowed in 2.x operators and sources."));
66+
actual.onError(new NullPointerException("onSuccess called with null. 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("Emitter got a null throwable. Null values are generally not allowed in 2.x operators and sources.");
82+
t = new NullPointerException("onError called with null. 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)