Skip to content

Commit 5d8b0ac

Browse files
hanschuaakarnokd
authored andcommitted
2.X: Fix disposed LambdaObserver onError to route to global error handler (#6036)
1 parent f3c8862 commit 5d8b0ac

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/main/java/io/reactivex/internal/observers/LambdaObserver.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ public void onError(Throwable t) {
7979
Exceptions.throwIfFatal(e);
8080
RxJavaPlugins.onError(new CompositeException(t, e));
8181
}
82+
} else {
83+
RxJavaPlugins.onError(t);
8284
}
8385
}
8486

src/test/java/io/reactivex/internal/observers/LambdaObserverTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import static org.junit.Assert.*;
1717

18+
import java.io.IOException;
1819
import java.util.*;
1920

2021
import io.reactivex.internal.functions.Functions;
@@ -363,4 +364,32 @@ public void customOnErrorShouldReportCustomOnError() {
363364

364365
assertTrue(o.hasCustomOnError());
365366
}
367+
368+
@Test
369+
public void disposedObserverShouldReportErrorOnGlobalErrorHandler() {
370+
List<Throwable> errors = TestHelper.trackPluginErrors();
371+
try {
372+
final List<Throwable> observerErrors = Collections.synchronizedList(new ArrayList<Throwable>());
373+
374+
LambdaObserver<Integer> o = new LambdaObserver<Integer>(Functions.<Integer>emptyConsumer(),
375+
new Consumer<Throwable>() {
376+
@Override
377+
public void accept(Throwable t) {
378+
observerErrors.add(t);
379+
}
380+
},
381+
Functions.EMPTY_ACTION,
382+
Functions.<Disposable>emptyConsumer());
383+
384+
o.dispose();
385+
o.onError(new IOException());
386+
o.onError(new IOException());
387+
388+
assertTrue(observerErrors.isEmpty());
389+
TestHelper.assertUndeliverable(errors, 0, IOException.class);
390+
TestHelper.assertUndeliverable(errors, 1, IOException.class);
391+
} finally {
392+
RxJavaPlugins.reset();
393+
}
394+
}
366395
}

0 commit comments

Comments
 (0)