Skip to content

Commit

Permalink
Merge pull request ReactiveX#2156 from zsxwing/map-swallow-fatal-exce…
Browse files Browse the repository at this point in the history
…ptions

Fix the issue that map may swallow fatal exceptions
  • Loading branch information
benjchristensen committed Dec 24, 2014
2 parents a683fcc + 3563021 commit 2f821d8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/rx/internal/operators/OperatorMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import rx.Observable.Operator;
import rx.Subscriber;
import rx.exceptions.Exceptions;
import rx.exceptions.OnErrorThrowable;
import rx.functions.Func1;

Expand Down Expand Up @@ -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));
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/rx/internal/operators/OperatorMapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,24 @@ private static Map<String, String> getMap(String prefix) {
m.put("lastName", prefix + "Last");
return m;
}

@Test(expected = OnErrorNotImplementedException.class)
public void testShouldNotSwallowOnErrorNotImplementedException() {
Observable.just("a", "b").flatMap(new Func1<String, Observable<String>>() {
@Override
public Observable<String> call(String s) {
return Observable.just(s + "1", s + "2");
}
}).flatMap(new Func1<String, Observable<String>>() {
@Override
public Observable<String> call(String s) {
return Observable.error(new Exception("test"));
}
}).forEach(new Action1<String>() {
@Override
public void call(String s) {
System.out.println(s);
}
});
}
}

0 comments on commit 2f821d8

Please sign in to comment.