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: Delegate null Collections down to onError in toList #4731

Merged
merged 1 commit into from
Oct 19, 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 @@ -13,6 +13,7 @@

package io.reactivex.internal.operators.flowable;

import io.reactivex.internal.functions.ObjectHelper;
import java.util.Collection;
import java.util.concurrent.Callable;

Expand All @@ -33,7 +34,7 @@ public FlowableToList(Publisher<T> source, Callable<U> collectionSupplier) {
protected void subscribeActual(Subscriber<? super U> s) {
U coll;
try {
coll = collectionSupplier.call();
coll = ObjectHelper.requireNonNull(collectionSupplier.call(), "The collectionSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources.");
} catch (Throwable e) {
Exceptions.throwIfFatal(e);
EmptySubscription.error(e, s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package io.reactivex.internal.operators.flowable;

import io.reactivex.internal.functions.ObjectHelper;
import java.util.Collection;
import java.util.concurrent.Callable;

Expand Down Expand Up @@ -47,7 +48,7 @@ public FlowableToListSingle(Publisher<T> source, Callable<U> collectionSupplier)
protected void subscribeActual(SingleObserver<? super U> s) {
U coll;
try {
coll = collectionSupplier.call();
coll = ObjectHelper.requireNonNull(collectionSupplier.call(), "The collectionSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, is there a place where null values are allowed? The use of "generally" seems to imply such.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and yes I know we use this wording everywhere)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using's resource supplier can return null, we don't complain about null resources.

} catch (Throwable e) {
Exceptions.throwIfFatal(e);
EmptyDisposable.error(e, s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public ObservableToList(ObservableSource<T> source, Callable<U> collectionSuppli
public void subscribeActual(Observer<? super U> t) {
U coll;
try {
coll = ObjectHelper.requireNonNull(collectionSupplier.call(), "The collectionSupplier returned a null Collection");
coll = ObjectHelper.requireNonNull(collectionSupplier.call(), "The collectionSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources.");
} catch (Throwable e) {
Exceptions.throwIfFatal(e);
EmptyDisposable.error(e, t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package io.reactivex.internal.operators.observable;

import io.reactivex.internal.functions.ObjectHelper;
import java.util.*;
import java.util.concurrent.Callable;

Expand Down Expand Up @@ -48,7 +49,7 @@ public ObservableToListSingle(ObservableSource<T> source, Callable<U> collection
public void subscribeActual(SingleObserver<? super U> t) {
U coll;
try {
coll = collectionSupplier.call();
coll = ObjectHelper.requireNonNull(collectionSupplier.call(), "The collectionSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources.");
} catch (Throwable e) {
Exceptions.throwIfFatal(e);
EmptyDisposable.error(e, t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,22 @@ public Collection<Integer> call() throws Exception {
.assertFailure(TestException.class);
}

@SuppressWarnings("unchecked")
@Test
public void collectionSupplierReturnsNull() {
Flowable.just(1)
.toList(new Callable<Collection<Integer>>() {
@Override
public Collection<Integer> call() throws Exception {
return null;
}
})
.toFlowable()
.test()
.assertFailure(NullPointerException.class)
.assertErrorMessage("The collectionSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources.");
}

@SuppressWarnings("unchecked")
@Test
public void singleCollectionSupplierThrows() {
Expand All @@ -358,4 +374,19 @@ public Collection<Integer> call() throws Exception {
.test()
.assertFailure(TestException.class);
}
}

@SuppressWarnings("unchecked")
@Test
public void singleCollectionSupplierReturnsNull() {
Flowable.just(1)
.toList(new Callable<Collection<Integer>>() {
@Override
public Collection<Integer> call() throws Exception {
return null;
}
})
.test()
.assertFailure(NullPointerException.class)
.assertErrorMessage("The collectionSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,22 @@ public Collection<Integer> call() throws Exception {
.assertFailure(TestException.class);
}

@SuppressWarnings("unchecked")
@Test
public void collectionSupplierReturnsNull() {
Observable.just(1)
.toList(new Callable<Collection<Integer>>() {
@Override
public Collection<Integer> call() throws Exception {
return null;
}
})
.toObservable()
.test()
.assertFailure(NullPointerException.class)
.assertErrorMessage("The collectionSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources.");
}

@SuppressWarnings("unchecked")
@Test
public void singleCollectionSupplierThrows() {
Expand All @@ -239,4 +255,19 @@ public Collection<Integer> call() throws Exception {
.test()
.assertFailure(TestException.class);
}
}

@SuppressWarnings("unchecked")
@Test
public void singleCollectionSupplierReturnsNull() {
Observable.just(1)
.toList(new Callable<Collection<Integer>>() {
@Override
public Collection<Integer> call() throws Exception {
return null;
}
})
.test()
.assertFailure(NullPointerException.class)
.assertErrorMessage("The collectionSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources.");
}
}