Skip to content

Commit 09b1389

Browse files
authored
1.x: SafeSubscriber not to call RxJavaHooks before delivering the (#4641)
original error.
1 parent 2b47efe commit 09b1389

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/main/java/rx/observers/SafeSubscriber.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import rx.Subscriber;
2121
import rx.exceptions.*;
22-
import rx.plugins.RxJavaHooks;
22+
import rx.plugins.*;
2323

2424
/**
2525
* {@code SafeSubscriber} is a wrapper around {@code Subscriber} that ensures that the {@code Subscriber}
@@ -146,8 +146,9 @@ public void onNext(T args) {
146146
*
147147
* @see <a href="https://github.com/ReactiveX/RxJava/issues/630">the report of this bug</a>
148148
*/
149+
@SuppressWarnings("deprecation")
149150
protected void _onError(Throwable e) { // NOPMD
150-
RxJavaHooks.onError(e);
151+
RxJavaPlugins.getInstance().getErrorHandler().handleError(e);
151152
try {
152153
actual.onError(e);
153154
} catch (OnErrorNotImplementedException e2) { // NOPMD

src/test/java/rx/plugins/RxJavaHooksTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,4 +1084,25 @@ public Completable.Operator onLift(Completable.Operator lift) {
10841084
}
10851085
}
10861086

1087+
@Test
1088+
public void noCallToHooksOnPlainError() {
1089+
1090+
final boolean[] called = { false };
1091+
1092+
RxJavaHooks.setOnError(new Action1<Throwable>() {
1093+
@Override
1094+
public void call(Throwable t) {
1095+
called[0] = true;
1096+
}
1097+
});
1098+
1099+
try {
1100+
Observable.error(new TestException())
1101+
.subscribe(new TestSubscriber<Object>());
1102+
1103+
assertFalse(called[0]);
1104+
} finally {
1105+
RxJavaHooks.reset();
1106+
}
1107+
}
10871108
}

0 commit comments

Comments
 (0)