Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.x: Remove Maybe.onExceptionResumeNext #6844

Merged
merged 1 commit into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 1 addition & 32 deletions src/main/java/io/reactivex/rxjava3/core/Maybe.java
Original file line number Diff line number Diff line change
Expand Up @@ -3939,7 +3939,7 @@ public final Maybe<T> onErrorResumeWith(@NonNull MaybeSource<? extends T> next)
@SchedulerSupport(SchedulerSupport.NONE)
public final Maybe<T> onErrorResumeNext(@NonNull Function<? super Throwable, ? extends MaybeSource<? extends T>> resumeFunction) {
Objects.requireNonNull(resumeFunction, "resumeFunction is null");
return RxJavaPlugins.onAssembly(new MaybeOnErrorNext<>(this, resumeFunction, true));
return RxJavaPlugins.onAssembly(new MaybeOnErrorNext<>(this, resumeFunction));
}

/**
Expand Down Expand Up @@ -3996,37 +3996,6 @@ public final Maybe<T> onErrorReturnItem(@NonNull T item) {
return onErrorReturn(Functions.justFunction(item));
}

/**
* Resumes the flow with the given {@link MaybeSource} when the current {@code Maybe} fails
* with an {@link Exception} subclass instead of signaling the error via {@code onError}.
* <p>
* This differs from {@link #onErrorResumeNext} in that this one does not handle {@link java.lang.Throwable}
* or {@link java.lang.Error} but lets those continue through.
* <p>
* <img width="640" height="333" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/onExceptionResumeNextViaMaybe.png" alt="">
* <p>
* You can use this to prevent exceptions from propagating or to supply fallback data should exceptions be
* encountered.
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code onExceptionResumeNext} does not operate by default on a particular {@link Scheduler}.</dd>
* </dl>
*
* @param next
* the next {@code MaybeSource} that will take over if the current {@code Maybe} encounters
* an exception
* @return the new {@code Maybe} instance
* @throws NullPointerException if {@code next} is {@code null}
* @see <a href="http://reactivex.io/documentation/operators/catch.html">ReactiveX operators documentation: Catch</a>
*/
@CheckReturnValue
@NonNull
@SchedulerSupport(SchedulerSupport.NONE)
public final Maybe<T> onExceptionResumeNext(@NonNull MaybeSource<? extends T> next) {
Objects.requireNonNull(next, "next is null");
return RxJavaPlugins.onAssembly(new MaybeOnErrorNext<>(this, Functions.justFunction(next), false));
}

/**
* Nulls out references to the upstream producer and downstream {@link MaybeObserver} if
* the sequence is terminated or downstream calls {@code dispose()}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,15 @@ public final class MaybeOnErrorNext<T> extends AbstractMaybeWithUpstream<T, T> {

final Function<? super Throwable, ? extends MaybeSource<? extends T>> resumeFunction;

final boolean allowFatal;

public MaybeOnErrorNext(MaybeSource<T> source,
Function<? super Throwable, ? extends MaybeSource<? extends T>> resumeFunction,
boolean allowFatal) {
Function<? super Throwable, ? extends MaybeSource<? extends T>> resumeFunction) {
super(source);
this.resumeFunction = resumeFunction;
this.allowFatal = allowFatal;
}

@Override
protected void subscribeActual(MaybeObserver<? super T> observer) {
source.subscribe(new OnErrorNextMaybeObserver<>(observer, resumeFunction, allowFatal));
source.subscribe(new OnErrorNextMaybeObserver<>(observer, resumeFunction));
}

static final class OnErrorNextMaybeObserver<T>
Expand All @@ -56,14 +52,10 @@ static final class OnErrorNextMaybeObserver<T>

final Function<? super Throwable, ? extends MaybeSource<? extends T>> resumeFunction;

final boolean allowFatal;

OnErrorNextMaybeObserver(MaybeObserver<? super T> actual,
Function<? super Throwable, ? extends MaybeSource<? extends T>> resumeFunction,
boolean allowFatal) {
Function<? super Throwable, ? extends MaybeSource<? extends T>> resumeFunction) {
this.downstream = actual;
this.resumeFunction = resumeFunction;
this.allowFatal = allowFatal;
}

@Override
Expand All @@ -90,10 +82,6 @@ public void onSuccess(T value) {

@Override
public void onError(Throwable e) {
if (!allowFatal && !(e instanceof Exception)) {
downstream.onError(e);
return;
}
MaybeSource<? extends T> m;

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,6 @@ public void onErrorResumeNext() {
.assertResult(1);
}

@Test
public void onExceptionResumeNext() {
Maybe.error(new TestException())
.onExceptionResumeNext(Maybe.just(1))
.test()
.assertResult(1);
}

@Test
public void onExceptionResumeNextPassthrough() {
Maybe.error(new AssertionError())
.onExceptionResumeNext(Maybe.just(1))
.test()
.assertFailure(AssertionError.class);
}

@Test
public void onErrorResumeNextFunctionThrows() {
TestHelper.assertCompositeExceptions(Maybe.error(new TestException())
Expand Down