Skip to content

Fix NPE when iterable is null #1750

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

Merged
merged 1 commit into from
Oct 13, 2014
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 @@ -35,14 +35,14 @@ public final class OnSubscribeFromIterable<T> implements OnSubscribe<T> {
final Iterable<? extends T> is;

public OnSubscribeFromIterable(Iterable<? extends T> iterable) {
if (iterable == null) {
throw new NullPointerException("iterable must not be null");
}
this.is = iterable;
}

@Override
public void call(final Subscriber<? super T> o) {
if (is == null) {
o.onCompleted();
}
final Iterator<? extends T> it = is.iterator();
o.setProducer(new IterableProducer<T>(o, it));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,9 @@

public class OnSubscribeFromIterableTest {

@Test
@Test(expected = NullPointerException.class)
public void testNull() {
Observable<String> observable = Observable.create(new OnSubscribeFromIterable<String>(null));

@SuppressWarnings("unchecked")
Observer<String> observer = mock(Observer.class);
observable.subscribe(observer);
verify(observer, Mockito.never()).onNext(any(String.class));
verify(observer, Mockito.never()).onError(any(Throwable.class));
verify(observer, times(1)).onCompleted();
Observable.create(new OnSubscribeFromIterable<String>(null));
}

@Test
Expand Down