diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java index 2dc316d1e9..f3dc0c58b8 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowableConcatMap.java @@ -520,10 +520,13 @@ void drain() { vr = supplier.call(); } catch (Throwable e) { Exceptions.throwIfFatal(e); - upstream.cancel(); errors.addThrowable(e); - downstream.onError(errors.terminate()); - return; + if (!veryEnd) { + upstream.cancel(); + downstream.onError(errors.terminate()); + return; + } + vr = null; } if (vr == null) { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java index eba09e564f..d9fe79977f 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java @@ -15,14 +15,14 @@ import static org.junit.Assert.assertEquals; -import java.util.concurrent.TimeUnit; +import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; import org.reactivestreams.Publisher; import io.reactivex.*; -import io.reactivex.exceptions.TestException; +import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.internal.operators.flowable.FlowableConcatMap.WeakScalarSubscription; import io.reactivex.schedulers.Schedulers; @@ -168,4 +168,42 @@ public void run() throws Exception { assertEquals(0, counter.get()); } + + @Test + public void delayErrorCallableTillTheEnd() { + Flowable.just(1, 2, 3, 101, 102, 23, 890, 120, 32) + .concatMapDelayError(new Function>() { + @Override public Flowable apply(final Integer integer) throws Exception { + return Flowable.fromCallable(new Callable() { + @Override public Integer call() throws Exception { + if (integer >= 100) { + throw new NullPointerException("test null exp"); + } + return integer; + } + }); + } + }) + .test() + .assertFailure(CompositeException.class, 1, 2, 3, 23, 32); + } + + @Test + public void delayErrorCallableEager() { + Flowable.just(1, 2, 3, 101, 102, 23, 890, 120, 32) + .concatMapDelayError(new Function>() { + @Override public Flowable apply(final Integer integer) throws Exception { + return Flowable.fromCallable(new Callable() { + @Override public Integer call() throws Exception { + if (integer >= 100) { + throw new NullPointerException("test null exp"); + } + return integer; + } + }); + } + }, 2, false) + .test() + .assertFailure(NullPointerException.class, 1, 2, 3); + } }