alexandroid/decompiled/jadx/sources/com/google/common/base/Throwables.java
KaKi87 a47fad5135 📦 Add decompiled Alexa 2.2.730155.0 (jadx, apktool, Hermes strings)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 00:04:16 +01:00

275 lines
8.8 KiB
Java

package com.google.common.base;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.annotations.J2ktIncompatible;
import com.google.common.annotations.VisibleForTesting;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import okio.Buffer$$ExternalSyntheticBUOutline0;
import rx.Single$$ExternalSyntheticBUOutline0;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
@GwtCompatible(emulated = true)
/* loaded from: classes8.dex */
public final class Throwables {
@J2ktIncompatible
@GwtIncompatible
private static final String JAVA_LANG_ACCESS_CLASSNAME = "sun.misc.JavaLangAccess";
@VisibleForTesting
@J2ktIncompatible
@GwtIncompatible
static final String SHARED_SECRETS_CLASSNAME = "sun.misc.SharedSecrets";
@J2ktIncompatible
@GwtIncompatible
private static final Method getStackTraceDepthMethod;
@J2ktIncompatible
@GwtIncompatible
private static final Method getStackTraceElementMethod;
@J2ktIncompatible
@GwtIncompatible
private static final Object jla;
static {
Object jla2 = getJla();
jla = jla2;
getStackTraceElementMethod = jla2 == null ? null : getGetMethod();
getStackTraceDepthMethod = jla2 != null ? getSizeMethod(jla2) : null;
}
private Throwables() {
}
public static List<Throwable> getCausalChain(Throwable th) {
Preconditions.checkNotNull(th);
ArrayList arrayList = new ArrayList(4);
arrayList.add(th);
boolean z = false;
Throwable th2 = th;
while (true) {
th = th.getCause();
if (th == null) {
return Collections.unmodifiableList(arrayList);
}
arrayList.add(th);
if (th == th2) {
Single$$ExternalSyntheticBUOutline0.m("Loop in causal chain detected.", th);
return null;
}
if (z) {
th2 = th2.getCause();
}
z = !z;
}
}
@GwtIncompatible
public static <X extends Throwable> X getCauseAs(Throwable th, Class<X> cls) {
try {
return cls.cast(th.getCause());
} catch (ClassCastException e) {
e.initCause(th);
throw e;
}
}
@J2ktIncompatible
@GwtIncompatible
private static Method getGetMethod() {
return getJlaMethod("getStackTraceElement", Throwable.class, Integer.TYPE);
}
@J2ktIncompatible
@GwtIncompatible
private static Object getJla() {
try {
return Class.forName(SHARED_SECRETS_CLASSNAME, false, null).getMethod("getJavaLangAccess", null).invoke(null, null);
} catch (ThreadDeath e) {
throw e;
} catch (Throwable unused) {
return null;
}
}
@J2ktIncompatible
@GwtIncompatible
private static Method getJlaMethod(String str, Class<?>... clsArr) throws ThreadDeath {
try {
return Class.forName(JAVA_LANG_ACCESS_CLASSNAME, false, null).getMethod(str, clsArr);
} catch (ThreadDeath e) {
throw e;
} catch (Throwable unused) {
return null;
}
}
public static Throwable getRootCause(Throwable th) {
boolean z = false;
Throwable th2 = th;
while (true) {
Throwable cause = th.getCause();
if (cause == null) {
return th;
}
if (cause == th2) {
Single$$ExternalSyntheticBUOutline0.m("Loop in causal chain detected.", cause);
return null;
}
if (z) {
th2 = th2.getCause();
}
z = !z;
th = cause;
}
}
@J2ktIncompatible
@GwtIncompatible
private static Method getSizeMethod(Object obj) {
try {
Method jlaMethod = getJlaMethod("getStackTraceDepth", Throwable.class);
if (jlaMethod == null) {
return null;
}
jlaMethod.invoke(obj, new Throwable());
return jlaMethod;
} catch (IllegalAccessException | UnsupportedOperationException | InvocationTargetException unused) {
return null;
}
}
@GwtIncompatible
public static String getStackTraceAsString(Throwable th) {
StringWriter stringWriter = new StringWriter();
th.printStackTrace(new PrintWriter(stringWriter));
return stringWriter.toString();
}
/* JADX INFO: Access modifiers changed from: private */
@J2ktIncompatible
@GwtIncompatible
public static Object invokeAccessibleNonThrowingMethod(Method method, Object obj, Object... objArr) {
try {
return method.invoke(obj, objArr);
} catch (IllegalAccessException e) {
Buffer$$ExternalSyntheticBUOutline0.m((Throwable) e);
return null;
} catch (InvocationTargetException e2) {
throw propagate(e2.getCause());
}
}
@J2ktIncompatible
@GwtIncompatible
private static List<StackTraceElement> jlaStackTrace(final Throwable th) {
Preconditions.checkNotNull(th);
return new AbstractList<StackTraceElement>() { // from class: com.google.common.base.Throwables.1
@Override // java.util.AbstractList, java.util.List
public StackTraceElement get(int i) {
Method method = Throwables.getStackTraceElementMethod;
java.util.Objects.requireNonNull(method);
Object obj = Throwables.jla;
java.util.Objects.requireNonNull(obj);
return (StackTraceElement) Throwables.invokeAccessibleNonThrowingMethod(method, obj, th, Integer.valueOf(i));
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.List
public int size() {
Method method = Throwables.getStackTraceDepthMethod;
java.util.Objects.requireNonNull(method);
Object obj = Throwables.jla;
java.util.Objects.requireNonNull(obj);
return ((Integer) Throwables.invokeAccessibleNonThrowingMethod(method, obj, th)).intValue();
}
};
}
@J2ktIncompatible
@GwtIncompatible
@Deprecated
public static List<StackTraceElement> lazyStackTrace(Throwable th) {
return lazyStackTraceIsLazy() ? jlaStackTrace(th) : Collections.unmodifiableList(Arrays.asList(th.getStackTrace()));
}
@J2ktIncompatible
@GwtIncompatible
@Deprecated
public static boolean lazyStackTraceIsLazy() {
return (getStackTraceElementMethod == null || getStackTraceDepthMethod == null) ? false : true;
}
@GwtIncompatible
@Deprecated
@CanIgnoreReturnValue
@J2ktIncompatible
public static RuntimeException propagate(Throwable th) {
throwIfUnchecked(th);
throw new RuntimeException(th);
}
@GwtIncompatible
@Deprecated
@J2ktIncompatible
public static <X extends Throwable> void propagateIfInstanceOf(Throwable th, Class<X> cls) throws Throwable {
if (th != null) {
throwIfInstanceOf(th, cls);
}
}
@GwtIncompatible
@Deprecated
@J2ktIncompatible
public static <X1 extends Throwable, X2 extends Throwable> void propagateIfPossible(Throwable th, Class<X1> cls, Class<X2> cls2) throws Throwable, Throwable {
Preconditions.checkNotNull(cls2);
propagateIfInstanceOf(th, cls);
propagateIfPossible(th, cls2);
}
@GwtIncompatible
public static <X extends Throwable> void throwIfInstanceOf(Throwable th, Class<X> cls) throws Throwable {
Preconditions.checkNotNull(th);
if (cls.isInstance(th)) {
throw cls.cast(th);
}
}
public static void throwIfUnchecked(Throwable th) {
Preconditions.checkNotNull(th);
if (th instanceof RuntimeException) {
throw ((RuntimeException) th);
}
if (th instanceof Error) {
throw ((Error) th);
}
}
@GwtIncompatible
@Deprecated
@J2ktIncompatible
public static <X extends Throwable> void propagateIfPossible(Throwable th, Class<X> cls) throws Throwable {
propagateIfInstanceOf(th, cls);
propagateIfPossible(th);
}
@J2ktIncompatible
@GwtIncompatible
@Deprecated
public static void propagateIfPossible(Throwable th) {
if (th != null) {
throwIfUnchecked(th);
}
}
}