From 3563021690b04d18c2419d8b2c2f1cf8b5065be4 Mon Sep 17 00:00:00 2001 From: zsxwing Date: Mon, 22 Dec 2014 16:07:43 +0800 Subject: [PATCH] Fix the issue that map may swallow fatal exceptions --- .../rx/internal/operators/OperatorMap.java | 2 ++ .../internal/operators/OperatorMapTest.java | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/main/java/rx/internal/operators/OperatorMap.java b/src/main/java/rx/internal/operators/OperatorMap.java index 1a34918440..1f82a21764 100644 --- a/src/main/java/rx/internal/operators/OperatorMap.java +++ b/src/main/java/rx/internal/operators/OperatorMap.java @@ -17,6 +17,7 @@ import rx.Observable.Operator; import rx.Subscriber; +import rx.exceptions.Exceptions; import rx.exceptions.OnErrorThrowable; import rx.functions.Func1; @@ -53,6 +54,7 @@ public void onNext(T t) { try { o.onNext(transformer.call(t)); } catch (Throwable e) { + Exceptions.throwIfFatal(e); onError(OnErrorThrowable.addValueAsLastCause(e, t)); } } diff --git a/src/test/java/rx/internal/operators/OperatorMapTest.java b/src/test/java/rx/internal/operators/OperatorMapTest.java index a1de9588af..bcca50fab8 100644 --- a/src/test/java/rx/internal/operators/OperatorMapTest.java +++ b/src/test/java/rx/internal/operators/OperatorMapTest.java @@ -319,4 +319,24 @@ private static Map getMap(String prefix) { m.put("lastName", prefix + "Last"); return m; } + + @Test(expected = OnErrorNotImplementedException.class) + public void testShouldNotSwallowOnErrorNotImplementedException() { + Observable.just("a", "b").flatMap(new Func1>() { + @Override + public Observable call(String s) { + return Observable.just(s + "1", s + "2"); + } + }).flatMap(new Func1>() { + @Override + public Observable call(String s) { + return Observable.error(new Exception("test")); + } + }).forEach(new Action1() { + @Override + public void call(String s) { + System.out.println(s); + } + }); + } }