Skip to content

Commit 2f821d8

Browse files
Merge pull request #2156 from zsxwing/map-swallow-fatal-exceptions
Fix the issue that map may swallow fatal exceptions
2 parents a683fcc + 3563021 commit 2f821d8

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/main/java/rx/internal/operators/OperatorMap.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import rx.Observable.Operator;
1919
import rx.Subscriber;
20+
import rx.exceptions.Exceptions;
2021
import rx.exceptions.OnErrorThrowable;
2122
import rx.functions.Func1;
2223

@@ -53,6 +54,7 @@ public void onNext(T t) {
5354
try {
5455
o.onNext(transformer.call(t));
5556
} catch (Throwable e) {
57+
Exceptions.throwIfFatal(e);
5658
onError(OnErrorThrowable.addValueAsLastCause(e, t));
5759
}
5860
}

src/test/java/rx/internal/operators/OperatorMapTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,4 +319,24 @@ private static Map<String, String> getMap(String prefix) {
319319
m.put("lastName", prefix + "Last");
320320
return m;
321321
}
322+
323+
@Test(expected = OnErrorNotImplementedException.class)
324+
public void testShouldNotSwallowOnErrorNotImplementedException() {
325+
Observable.just("a", "b").flatMap(new Func1<String, Observable<String>>() {
326+
@Override
327+
public Observable<String> call(String s) {
328+
return Observable.just(s + "1", s + "2");
329+
}
330+
}).flatMap(new Func1<String, Observable<String>>() {
331+
@Override
332+
public Observable<String> call(String s) {
333+
return Observable.error(new Exception("test"));
334+
}
335+
}).forEach(new Action1<String>() {
336+
@Override
337+
public void call(String s) {
338+
System.out.println(s);
339+
}
340+
});
341+
}
322342
}

0 commit comments

Comments
 (0)