package s.a; import c.q.a.k.a; import d0.b; import d0.k; import d0.l; import d0.z.d.m; import java.util.concurrent.CancellationException; import kotlin.Unit; import kotlin.coroutines.Continuation; import kotlin.coroutines.CoroutineContext; import kotlinx.coroutines.Job; import s.a.a.g; import s.a.b2.h; import s.a.b2.i; /* compiled from: DispatchedTask.kt */ public abstract class i0 extends h { public int k; public i0(int i) { this.k = i; } public void c(Object obj, Throwable th) { } public abstract Continuation d(); public Throwable f(Object obj) { if (!(obj instanceof v)) { obj = null; } v vVar = (v) obj; if (vVar != null) { return vVar.b; } return null; } /* JADX DEBUG: Multi-variable search result rejected for r1v0, resolved type: java.lang.Object */ /* JADX WARN: Multi-variable type inference failed */ public T l(Object obj) { return obj; } public final void m(Throwable th, Throwable th2) { if (th != null || th2 != null) { if (!(th == null || th2 == null)) { b.addSuppressed(th, th2); } if (th == null) { th = th2; } m.checkNotNull(th); a.x(d().getContext(), new b0("Fatal exception in coroutines machinery for " + this + ". Please read KDoc to 'handleFatalException' method and report this incident to maintainers", th)); } } public abstract Object n(); @Override // java.lang.Runnable public final void run() { Object obj; Object obj2; i iVar = this.j; try { Continuation d = d(); if (d != null) { g gVar = (g) d; Continuation continuation = gVar.q; CoroutineContext context = continuation.getContext(); Object n = n(); Object b = s.a.a.a.b(context, gVar.o); try { Throwable f = f(n); Job job = (f != null || !a.C(this.k)) ? null : (Job) context.get(Job.h); if (job != null && !job.a()) { CancellationException p = job.p(); c(n, p); k.a aVar = k.i; continuation.resumeWith(k.m78constructorimpl(l.createFailure(p))); } else if (f != null) { k.a aVar2 = k.i; continuation.resumeWith(k.m78constructorimpl(l.createFailure(f))); } else { T l = l(n); k.a aVar3 = k.i; continuation.resumeWith(k.m78constructorimpl(l)); } Unit unit = Unit.a; try { k.a aVar4 = k.i; iVar.e(); obj2 = k.m78constructorimpl(unit); } catch (Throwable th) { k.a aVar5 = k.i; obj2 = k.m78constructorimpl(l.createFailure(th)); } m(null, k.m80exceptionOrNullimpl(obj2)); return; } finally { s.a.a.a.a(context, b); } } else { throw new NullPointerException("null cannot be cast to non-null type kotlinx.coroutines.internal.DispatchedContinuation"); } } catch (Throwable th2) { k.a aVar6 = k.i; obj = k.m78constructorimpl(l.createFailure(th2)); } m(th, k.m80exceptionOrNullimpl(obj)); } }