Skip to content

Commit b0460d0

Browse files
Merge pull request ReactiveX#1015 from benjchristensen/safe-subscribe
Remove Redundant protectivelyWrap Method
2 parents c09efd8 + 0ab352f commit b0460d0

File tree

1 file changed

+12
-40
lines changed

1 file changed

+12
-40
lines changed

rxjava-core/src/main/java/rx/Observable.java

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5367,17 +5367,6 @@ public final <R> Observable<R> parallel(final Func1<Observable<T>, Observable<R>
53675367
return lift(new OperatorParallel<T, R>(f, s));
53685368
}
53695369

5370-
/**
5371-
* Protects against errors being thrown from Observer implementations and ensures
5372-
* onNext/onError/onCompleted contract compliance.
5373-
* <p>
5374-
* See https://github.com/Netflix/RxJava/issues/216 for a discussion on "Guideline 6.4: Protect calls to
5375-
* user code from within an Observer"
5376-
*/
5377-
private Subscription protectivelyWrapAndSubscribe(Subscriber<? super T> o) {
5378-
return subscribe(new SafeSubscriber<T>(o));
5379-
}
5380-
53815370
/**
53825371
* Returns a {@link ConnectableObservable}, which waits until its {@link ConnectableObservable#connect connect} method is called before it begins emitting items to those {@link Observer}s that
53835372
* have subscribed to it.
@@ -6704,7 +6693,7 @@ public final Observable<T> startWith(T[] values, Scheduler scheduler) {
67046693
* if the Observable tries to call {@code onError}
67056694
*/
67066695
public final Subscription subscribe() {
6707-
return protectivelyWrapAndSubscribe(new Subscriber<T>() {
6696+
return subscribe(new Subscriber<T>() {
67086697

67096698
@Override
67106699
public final void onCompleted() {
@@ -6743,13 +6732,7 @@ public final Subscription subscribe(final Action1<? super T> onNext) {
67436732
throw new IllegalArgumentException("onNext can not be null");
67446733
}
67456734

6746-
/**
6747-
* Wrapping since raw functions provided by the user are being invoked.
6748-
*
6749-
* See https://github.com/Netflix/RxJava/issues/216 for discussion on "Guideline 6.4: Protect calls to
6750-
* user code from within an Observer"
6751-
*/
6752-
return protectivelyWrapAndSubscribe(new Subscriber<T>() {
6735+
return subscribe(new Subscriber<T>() {
67536736

67546737
@Override
67556738
public final void onCompleted() {
@@ -6793,13 +6776,7 @@ public final Subscription subscribe(final Action1<? super T> onNext, final Actio
67936776
throw new IllegalArgumentException("onError can not be null");
67946777
}
67956778

6796-
/**
6797-
* Wrapping since raw functions provided by the user are being invoked.
6798-
*
6799-
* See https://github.com/Netflix/RxJava/issues/216 for discussion on
6800-
* "Guideline 6.4: Protect calls to user code from within an Observer"
6801-
*/
6802-
return protectivelyWrapAndSubscribe(new Subscriber<T>() {
6779+
return subscribe(new Subscriber<T>() {
68036780

68046781
@Override
68056782
public final void onCompleted() {
@@ -6850,12 +6827,7 @@ public final Subscription subscribe(final Action1<? super T> onNext, final Actio
68506827
throw new IllegalArgumentException("onComplete can not be null");
68516828
}
68526829

6853-
/**
6854-
* Wrapping since raw functions provided by the user are being invoked.
6855-
*
6856-
* See https://github.com/Netflix/RxJava/issues/216 for discussion on "Guideline 6.4: Protect calls to user code from within an Observer"
6857-
*/
6858-
return protectivelyWrapAndSubscribe(new Subscriber<T>() {
6830+
return subscribe(new Subscriber<T>() {
68596831

68606832
@Override
68616833
public final void onCompleted() {
@@ -7011,7 +6983,7 @@ public final Subscription unsafeSubscribe(Subscriber<? super T> subscriber) {
70116983
* For more information see the
70126984
* <a href="https://github.com/Netflix/RxJava/wiki/Observable">RxJava Wiki</a>
70136985
*
7014-
* @param observer
6986+
* @param subscriber
70156987
* the {@link Subscriber}
70166988
* @return a {@link Subscription} reference with which Subscribers that are {@link Observer}s can
70176989
* unsubscribe from the Observable
@@ -7024,11 +6996,11 @@ public final Subscription unsafeSubscribe(Subscriber<? super T> subscriber) {
70246996
* @throws RuntimeException
70256997
* if the {@link Subscriber}'s {@code onError} method itself threw a {@code Throwable}
70266998
*/
7027-
public final Subscription subscribe(Subscriber<? super T> observer) {
6999+
public final Subscription subscribe(Subscriber<? super T> subscriber) {
70287000
// allow the hook to intercept and/or decorate
70297001
OnSubscribe<T> onSubscribeFunction = hook.onSubscribeStart(this, onSubscribe);
70307002
// validate and proceed
7031-
if (observer == null) {
7003+
if (subscriber == null) {
70327004
throw new IllegalArgumentException("observer can not be null");
70337005
}
70347006
if (onSubscribeFunction == null) {
@@ -7044,12 +7016,12 @@ public final Subscription subscribe(Subscriber<? super T> observer) {
70447016
* to user code from within an Observer"
70457017
*/
70467018
// if not already wrapped
7047-
if (!(observer instanceof SafeSubscriber)) {
7019+
if (!(subscriber instanceof SafeSubscriber)) {
70487020
// assign to `observer` so we return the protected version
7049-
observer = new SafeSubscriber<T>(observer);
7021+
subscriber = new SafeSubscriber<T>(subscriber);
70507022
}
7051-
onSubscribeFunction.call(observer);
7052-
final Subscription returnSubscription = hook.onSubscribeReturn(observer);
7023+
onSubscribeFunction.call(subscriber);
7024+
final Subscription returnSubscription = hook.onSubscribeReturn(subscriber);
70537025
// we return it inside a Subscription so it can't be cast back to Subscriber
70547026
return Subscriptions.create(new Action0() {
70557027

@@ -7064,7 +7036,7 @@ public void call() {
70647036
Exceptions.throwIfFatal(e);
70657037
// if an unhandled error occurs executing the onSubscribe we will propagate it
70667038
try {
7067-
observer.onError(hook.onSubscribeError(e));
7039+
subscriber.onError(hook.onSubscribeError(e));
70687040
} catch (OnErrorNotImplementedException e2) {
70697041
// special handling when onError is not implemented ... we just rethrow
70707042
throw e2;

0 commit comments

Comments
 (0)