diff --git a/src/main/java/rx/internal/operators/OperatorScan.java b/src/main/java/rx/internal/operators/OperatorScan.java index 1cbdb53d54..5b132fd767 100644 --- a/src/main/java/rx/internal/operators/OperatorScan.java +++ b/src/main/java/rx/internal/operators/OperatorScan.java @@ -36,6 +36,9 @@ *

* Note that when you pass a seed to {@code scan} the resulting Observable will emit that seed as its * first emitted item. + * + * @param the aggregate and output type + * @param the input value type */ public final class OperatorScan implements Operator { @@ -192,7 +195,7 @@ public InitialProducer(R initialValue, Subscriber child) { q = new SpscLinkedAtomicQueue(); // new SpscUnboundedAtomicArrayQueue(8); } this.queue = q; - q.offer(initialValue); + q.offer(NotificationLite.instance().next(initialValue)); } @Override diff --git a/src/test/java/rx/internal/operators/OperatorScanTest.java b/src/test/java/rx/internal/operators/OperatorScanTest.java index ac7772753f..96c1b1dbe1 100644 --- a/src/test/java/rx/internal/operators/OperatorScanTest.java +++ b/src/test/java/rx/internal/operators/OperatorScanTest.java @@ -391,4 +391,39 @@ public Integer call(Integer t1, Integer t2) { ts.assertNotCompleted(); ts.assertValue(0); } + + @Test + public void testInitialValueNull() { + TestSubscriber ts = TestSubscriber.create(); + + Observable.range(1, 10).scan(null, new Func2() { + @Override + public Integer call(Integer t1, Integer t2) { + if (t1 == null) { + return t2; + } + return t1 + t2; + } + }).subscribe(ts); + + ts.assertValues(null, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55); + ts.assertNoErrors(); + ts.assertCompleted(); + } + + @Test + public void testEverythingIsNull() { + TestSubscriber ts = TestSubscriber.create(); + + Observable.range(1, 6).scan(null, new Func2() { + @Override + public Integer call(Integer t1, Integer t2) { + return null; + } + }).subscribe(ts); + + ts.assertValues(null, null, null, null, null, null, null); + ts.assertNoErrors(); + ts.assertCompleted(); + } }