Skip to content

Commit 57fde55

Browse files
vanniktechakarnokd
authored andcommitted
2.x: Distinct Operator - delegate null Collection down to onError (#4718)
1 parent c460dd5 commit 57fde55

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected void subscribeActual(Subscriber<? super T> observer) {
4444
Collection<? super K> collection;
4545

4646
try {
47-
collection = collectionSupplier.call();
47+
collection = ObjectHelper.requireNonNull(collectionSupplier.call(), "The collectionSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources.");
4848
} catch (Throwable ex) {
4949
Exceptions.throwIfFatal(ex);
5050
EmptySubscription.error(ex, observer);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected void subscribeActual(Observer<? super T> observer) {
4343
Collection<? super K> collection;
4444

4545
try {
46-
collection = collectionSupplier.call();
46+
collection = ObjectHelper.requireNonNull(collectionSupplier.call(), "The collectionSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources.");
4747
} catch (Throwable ex) {
4848
Exceptions.throwIfFatal(ex);
4949
EmptyDisposable.error(ex, observer);

src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,20 @@ public Collection<Object> call() throws Exception {
212212
.assertFailure(TestException.class);
213213
}
214214

215+
@Test
216+
public void collectionSupplierIsNull() {
217+
Flowable.just(1)
218+
.distinct(Functions.identity(), new Callable<Collection<Object>>() {
219+
@Override
220+
public Collection<Object> call() throws Exception {
221+
return null;
222+
}
223+
})
224+
.test()
225+
.assertFailure(NullPointerException.class)
226+
.assertErrorMessage("The collectionSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources.");
227+
}
228+
215229
@Test
216230
public void badSource() {
217231
List<Throwable> errors = TestHelper.trackPluginErrors();

src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,20 @@ public Collection<Object> call() throws Exception {
213213
.assertFailure(TestException.class);
214214
}
215215

216+
@Test
217+
public void collectionSupplierIsNull() {
218+
Observable.just(1)
219+
.distinct(Functions.identity(), new Callable<Collection<Object>>() {
220+
@Override
221+
public Collection<Object> call() throws Exception {
222+
return null;
223+
}
224+
})
225+
.test()
226+
.assertFailure(NullPointerException.class)
227+
.assertErrorMessage("The collectionSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources.");
228+
}
229+
216230
@Test
217231
public void badSource() {
218232
List<Throwable> errors = TestHelper.trackPluginErrors();

0 commit comments

Comments
 (0)