Skip to content

Commit 623acd9

Browse files
committed
Merge pull request #4 from davidmoten/npe-fix-1664
StringObservable.split NPE fixes as per RxJava #1664
2 parents 48760ac + deebdee commit 623acd9

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/main/java/rx/observables/StringObservable.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,14 +420,16 @@ public Subscriber<? super String> call(final Subscriber<? super String> o) {
420420

421421
@Override
422422
public void onCompleted() {
423-
output(leftOver);
423+
if (leftOver!=null)
424+
output(leftOver);
424425
if (!o.isUnsubscribed())
425426
o.onCompleted();
426427
}
427428

428429
@Override
429430
public void onError(Throwable e) {
430-
output(leftOver);
431+
if (leftOver!=null)
432+
output(leftOver);
431433
if (!o.isUnsubscribed())
432434
o.onError(e);
433435
}

src/test/java/rx/observables/StringObservableTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,24 @@ public void testSplitOnOh() {
142142
testSplit("boo:and:foo", "o", 0, "b", "", ":and:f");
143143
}
144144

145+
@Test
146+
public void testSplitOnEmptyStream() {
147+
assertEquals(0, (int) StringObservable.split(Observable.<String>empty(), "\n")
148+
.count().toBlocking().single());
149+
}
150+
151+
@Test
152+
public void testSplitOnStreamThatThrowsExceptionImmediately() {
153+
RuntimeException ex = new RuntimeException("boo");
154+
try {
155+
StringObservable.split(Observable.<String>error(ex), "\n")
156+
.count().toBlocking().single();
157+
fail();
158+
} catch (RuntimeException e) {
159+
assertEquals(ex, e);
160+
}
161+
}
162+
145163
public void testSplit(String str, String regex, int limit, String... parts) {
146164
testSplit(str, regex, 0, Observable.just(str), parts);
147165
for (int i = 0; i < str.length(); i++) {

0 commit comments

Comments
 (0)