Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.x fix Flowable.create() not reporting null values properly, unify #4583

Merged
merged 1 commit into from
Sep 22, 2016
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
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void onComplete() {
@Override
public void onError(Throwable t) {
if (t == null) {
t = new NullPointerException("Emitter got a null throwable. Null values are generally not allowed in 2.x operators and sources.");
t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
}
if (get() != DisposableHelper.DISPOSED) {
Disposable d = getAndSet(DisposableHelper.DISPOSED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void onNext(T t) {
return;
}
if (t == null) {
onError(new NullPointerException("Emitter got a null value. Null values are generally not allowed in 2.x operators and sources."));
onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."));
return;
}
if (get() == 0 && compareAndSet(0, 1)) {
Expand All @@ -134,7 +134,7 @@ public void onError(Throwable t) {
return;
}
if (t == null) {
t = new NullPointerException("Emitter got a null throwable. Null values are generally not allowed in 2.x operators and sources.");
t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
}
if (error.addThrowable(t)) {
done = true;
Expand Down Expand Up @@ -265,6 +265,7 @@ public void onComplete() {
@Override
public void onError(Throwable e) {
if (isCancelled()) {
RxJavaPlugins.onError(e);
return;
}
try {
Expand Down Expand Up @@ -337,7 +338,12 @@ public void onNext(T t) {
return;
}

actual.onNext(t);
if (t != null) {
actual.onNext(t);
} else {
onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."));
return;
}

for (;;) {
long r = get();
Expand All @@ -363,6 +369,11 @@ public final void onNext(T t) {
return;
}

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

if (get() != 0) {
actual.onNext(t);
BackpressureHelper.produced(this, 1);
Expand Down Expand Up @@ -426,12 +437,29 @@ static final class BufferAsyncEmitter<T> extends BaseEmitter<T> {

@Override
public void onNext(T t) {
if (done || isCancelled()) {
return;
}

if (t == null) {
onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."));
return;
}
queue.offer(t);
drain();
}

@Override
public void onError(Throwable e) {
if (done || isCancelled()) {
RxJavaPlugins.onError(e);
return;
}

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

error = e;
done = true;
drain();
Expand Down Expand Up @@ -552,12 +580,27 @@ static final class LatestAsyncEmitter<T> extends BaseEmitter<T> {

@Override
public void onNext(T t) {
if (done || isCancelled()) {
return;
}

if (t == null) {
onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."));
return;
}
queue.set(t);
drain();
}

@Override
public void onError(Throwable e) {
if (done || isCancelled()) {
RxJavaPlugins.onError(e);
return;
}
if (e == null) {
onError(new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources."));
}
error = e;
done = true;
drain();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void onSuccess(T value) {
if (d != DisposableHelper.DISPOSED) {
try {
if (value == null) {
actual.onError(new NullPointerException("Emitter got a null value. Null values are generally not allowed in 2.x operators and sources."));
actual.onError(new NullPointerException("onSuccess called with null. Null values are generally not allowed in 2.x operators and sources."));
} else {
actual.onSuccess(value);
}
Expand All @@ -85,7 +85,7 @@ public void onSuccess(T value) {
@Override
public void onError(Throwable t) {
if (t == null) {
t = new NullPointerException("Emitter got a null throwable. Null values are generally not allowed in 2.x operators and sources.");
t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
}
if (get() != DisposableHelper.DISPOSED) {
Disposable d = getAndSet(DisposableHelper.DISPOSED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ static final class CreateEmitter<T>
@Override
public void onNext(T t) {
if (t == null) {
onError(new NullPointerException("Emitter got a null value. Null values are generally not allowed in 2.x operators and sources."));
onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."));
return;
}
if (!isDisposed()) {
observer.onNext(t);
Expand All @@ -70,7 +71,7 @@ public void onNext(T t) {
@Override
public void onError(Throwable t) {
if (t == null) {
t = new NullPointerException("Emitter got a null throwable. Null values are generally not allowed in 2.x operators and sources.");
t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
}
if (!isDisposed()) {
try {
Expand Down Expand Up @@ -151,7 +152,7 @@ public void onNext(T t) {
return;
}
if (t == null) {
onError(new NullPointerException("t is null"));
onError(new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources."));
return;
}
if (get() == 0 && compareAndSet(0, 1)) {
Expand All @@ -178,7 +179,7 @@ public void onError(Throwable t) {
return;
}
if (t == null) {
t = new NullPointerException("t is null");
t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
}
if (error.addThrowable(t)) {
done = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void onSuccess(T value) {
if (d != DisposableHelper.DISPOSED) {
try {
if (value == null) {
actual.onError(new NullPointerException("Emitter got a null value. Null values are generally not allowed in 2.x operators and sources."));
actual.onError(new NullPointerException("onSuccess called with null. Null values are generally not allowed in 2.x operators and sources."));
} else {
actual.onSuccess(value);
}
Expand All @@ -79,7 +79,7 @@ public void onSuccess(T value) {
@Override
public void onError(Throwable t) {
if (t == null) {
t = new NullPointerException("Emitter got a null throwable. Null values are generally not allowed in 2.x operators and sources.");
t = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
}
if (get() != DisposableHelper.DISPOSED) {
Disposable d = getAndSet(DisposableHelper.DISPOSED);
Expand Down
Loading