package o; import java.util.ArrayDeque; import java.util.Iterator; import o.C13395fZS; /* renamed from: o.ghi, reason: case insensitive filesystem */ /* loaded from: classes.dex */ public final class C15120ghi { private static final String d; private static final String e; static { Object obj; Object obj2; try { C13395fZS.IeS ieS = C13395fZS.b; obj = C13395fZS.a(Class.forName("o.gbo").getCanonicalName()); } catch (Throwable th) { C13395fZS.IeS ieS2 = C13395fZS.b; C14957gcv.e(th, ""); obj = C13395fZS.a(new C13395fZS.LWm(th)); } e = (String) (C13395fZS.d(obj) == null ? obj : "o.gbo"); try { C13395fZS.IeS ieS3 = C13395fZS.b; obj2 = C13395fZS.a(Class.forName("o.ghi").getCanonicalName()); } catch (Throwable th2) { C13395fZS.IeS ieS4 = C13395fZS.b; C14957gcv.e(th2, ""); obj2 = C13395fZS.a(new C13395fZS.LWm(th2)); } d = (String) (C13395fZS.d(obj2) == null ? obj2 : "o.ghi"); } public static final E d(E e2) { E e3; StackTraceElement stackTraceElement; if (!C15045gfe.a() || (e3 = (E) c(e2)) == null) { return e2; } StackTraceElement[] stackTrace = e3.getStackTrace(); int length = stackTrace.length; int e4 = e(stackTrace, d); int e5 = e(stackTrace, e); int i = (length - e4) - (e5 == -1 ? 0 : length - e5); StackTraceElement[] stackTraceElementArr = new StackTraceElement[i]; for (int i2 = 0; i2 < i; i2++) { if (i2 != 0) { stackTraceElement = stackTrace[((e4 + 1) + i2) - 1]; } else { stackTraceElement = new StackTraceElement("\b\b\b(".concat("Coroutine boundary"), "\b", "\b", -1); } stackTraceElementArr[i2] = stackTraceElement; } e3.setStackTrace(stackTraceElementArr); return e3; } private static final E c(E e2) { E e3 = (E) ggQ.a(e2); if (e3 == null) { return null; } if ((e2 instanceof InterfaceC15002geR) || C14957gcv.b((Object) e3.getMessage(), (Object) e2.getMessage())) { return e3; } return null; } public static final E e(E e2) { E e3 = (E) e2.getCause(); if (e3 != null && C14957gcv.b(e3.getClass(), e2.getClass())) { for (StackTraceElement stackTraceElement : e2.getStackTrace()) { if (gdZ.e(stackTraceElement.getClassName(), "\b\b\b", false)) { return e3; } } } return e2; } private static final int e(StackTraceElement[] stackTraceElementArr, String str) { int length = stackTraceElementArr.length; for (int i = 0; i < length; i++) { if (C14957gcv.b((Object) str, (Object) stackTraceElementArr[i].getClassName())) { return i; } } return -1; } /* JADX WARN: Multi-variable type inference failed */ public static final /* synthetic */ Throwable c(Throwable th, InterfaceC14922gbx interfaceC14922gbx) { C13396fZU c13396fZU; StackTraceElement[] stackTraceElementArr; Throwable cause = th.getCause(); int i = 0; if (cause != null && C14957gcv.b(cause.getClass(), th.getClass())) { StackTraceElement[] stackTrace = th.getStackTrace(); int length = stackTrace.length; int i2 = 0; while (true) { if (i2 < length) { if (gdZ.e(stackTrace[i2].getClassName(), "\b\b\b", false)) { c13396fZU = new C13396fZU(cause, stackTrace); break; } i2++; } else { c13396fZU = new C13396fZU(th, new StackTraceElement[0]); break; } } } else { c13396fZU = new C13396fZU(th, new StackTraceElement[0]); } Throwable th2 = (Throwable) c13396fZU.d; StackTraceElement[] stackTraceElementArr2 = (StackTraceElement[]) c13396fZU.e; Throwable c = c(th2); if (c == null) { return th; } ArrayDeque arrayDeque = new ArrayDeque(); StackTraceElement stackTraceElement = interfaceC14922gbx.getStackTraceElement(); if (stackTraceElement != null) { arrayDeque.add(stackTraceElement); } while (true) { if (!(interfaceC14922gbx instanceof InterfaceC14922gbx)) { interfaceC14922gbx = null; } if (interfaceC14922gbx == null || (interfaceC14922gbx = interfaceC14922gbx.getCallerFrame()) == null) { break; } StackTraceElement stackTraceElement2 = interfaceC14922gbx.getStackTraceElement(); if (stackTraceElement2 != null) { arrayDeque.add(stackTraceElement2); } } if (arrayDeque.isEmpty()) { return th; } if (th2 != th) { int length2 = stackTraceElementArr2.length; int i3 = 0; while (true) { if (i3 >= length2) { i3 = -1; break; } if (gdZ.e(stackTraceElementArr2[i3].getClassName(), "\b\b\b", false)) { break; } i3++; } int i4 = i3 + 1; int length3 = stackTraceElementArr2.length - 1; if (i4 <= length3) { while (true) { StackTraceElement stackTraceElement3 = stackTraceElementArr2[length3]; StackTraceElement stackTraceElement4 = (StackTraceElement) arrayDeque.getLast(); if (stackTraceElement3.getLineNumber() == stackTraceElement4.getLineNumber() && C14957gcv.b((Object) stackTraceElement3.getMethodName(), (Object) stackTraceElement4.getMethodName()) && C14957gcv.b((Object) stackTraceElement3.getFileName(), (Object) stackTraceElement4.getFileName()) && C14957gcv.b((Object) stackTraceElement3.getClassName(), (Object) stackTraceElement4.getClassName())) { arrayDeque.removeLast(); } arrayDeque.addFirst(stackTraceElementArr2[length3]); if (length3 == i4) { break; } length3--; } } } arrayDeque.addFirst(new StackTraceElement("\b\b\b(".concat("Coroutine boundary"), "\b", "\b", -1)); StackTraceElement[] stackTrace2 = th2.getStackTrace(); int e2 = e(stackTrace2, e); if (e2 != -1) { StackTraceElement[] stackTraceElementArr3 = new StackTraceElement[arrayDeque.size() + e2]; for (int i5 = 0; i5 < e2; i5++) { stackTraceElementArr3[i5] = stackTrace2[i5]; } Iterator it = arrayDeque.iterator(); while (it.hasNext()) { stackTraceElementArr3[i + e2] = (StackTraceElement) it.next(); i++; } stackTraceElementArr = stackTraceElementArr3; } else { Object[] array = arrayDeque.toArray(new StackTraceElement[0]); if (array == null) { throw new NullPointerException("null cannot be cast to non-null type kotlin.Array"); } stackTraceElementArr = (StackTraceElement[]) array; } c.setStackTrace(stackTraceElementArr); return c; } }