jimu-decompiled/sources/io/reactivex/observers/SafeObserver.java
2025-05-13 19:24:51 +02:00

167 lines
5.2 KiB
Java

package io.reactivex.observers;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import io.reactivex.exceptions.CompositeException;
import io.reactivex.exceptions.Exceptions;
import io.reactivex.internal.disposables.DisposableHelper;
import io.reactivex.internal.disposables.EmptyDisposable;
import io.reactivex.plugins.RxJavaPlugins;
/* loaded from: classes2.dex */
public final class SafeObserver<T> implements Observer<T>, Disposable {
final Observer<? super T> a;
Disposable b;
boolean c;
public SafeObserver(Observer<? super T> observer) {
this.a = observer;
}
void a() {
NullPointerException nullPointerException = new NullPointerException("Subscription not set!");
try {
this.a.onSubscribe(EmptyDisposable.INSTANCE);
try {
this.a.onError(nullPointerException);
} catch (Throwable th) {
Exceptions.b(th);
RxJavaPlugins.b(new CompositeException(nullPointerException, th));
}
} catch (Throwable th2) {
Exceptions.b(th2);
RxJavaPlugins.b(new CompositeException(nullPointerException, th2));
}
}
void b() {
this.c = true;
NullPointerException nullPointerException = new NullPointerException("Subscription not set!");
try {
this.a.onSubscribe(EmptyDisposable.INSTANCE);
try {
this.a.onError(nullPointerException);
} catch (Throwable th) {
Exceptions.b(th);
RxJavaPlugins.b(new CompositeException(nullPointerException, th));
}
} catch (Throwable th2) {
Exceptions.b(th2);
RxJavaPlugins.b(new CompositeException(nullPointerException, th2));
}
}
@Override // io.reactivex.disposables.Disposable
public void dispose() {
this.b.dispose();
}
@Override // io.reactivex.Observer
public void onComplete() {
if (this.c) {
return;
}
this.c = true;
if (this.b == null) {
a();
return;
}
try {
this.a.onComplete();
} catch (Throwable th) {
Exceptions.b(th);
RxJavaPlugins.b(th);
}
}
@Override // io.reactivex.Observer
public void onError(Throwable th) {
if (this.c) {
RxJavaPlugins.b(th);
return;
}
this.c = true;
if (this.b != null) {
if (th == null) {
th = new NullPointerException("onError called with null. Null values are generally not allowed in 2.x operators and sources.");
}
try {
this.a.onError(th);
return;
} catch (Throwable th2) {
Exceptions.b(th2);
RxJavaPlugins.b(new CompositeException(th, th2));
return;
}
}
NullPointerException nullPointerException = new NullPointerException("Subscription not set!");
try {
this.a.onSubscribe(EmptyDisposable.INSTANCE);
try {
this.a.onError(new CompositeException(th, nullPointerException));
} catch (Throwable th3) {
Exceptions.b(th3);
RxJavaPlugins.b(new CompositeException(th, nullPointerException, th3));
}
} catch (Throwable th4) {
Exceptions.b(th4);
RxJavaPlugins.b(new CompositeException(th, nullPointerException, th4));
}
}
@Override // io.reactivex.Observer
public void onNext(T t) {
if (this.c) {
return;
}
if (this.b == null) {
b();
return;
}
if (t == null) {
NullPointerException nullPointerException = new NullPointerException("onNext called with null. Null values are generally not allowed in 2.x operators and sources.");
try {
this.b.dispose();
onError(nullPointerException);
return;
} catch (Throwable th) {
Exceptions.b(th);
onError(new CompositeException(nullPointerException, th));
return;
}
}
try {
this.a.onNext(t);
} catch (Throwable th2) {
Exceptions.b(th2);
try {
this.b.dispose();
onError(th2);
} catch (Throwable th3) {
Exceptions.b(th3);
onError(new CompositeException(th2, th3));
}
}
}
@Override // io.reactivex.Observer
public void onSubscribe(Disposable disposable) {
if (DisposableHelper.validate(this.b, disposable)) {
this.b = disposable;
try {
this.a.onSubscribe(this);
} catch (Throwable th) {
Exceptions.b(th);
this.c = true;
try {
disposable.dispose();
RxJavaPlugins.b(th);
} catch (Throwable th2) {
Exceptions.b(th2);
RxJavaPlugins.b(new CompositeException(th, th2));
}
}
}
}
}