alexandroid/decompiled/jadx/sources/rx/exceptions/CompositeException.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

254 lines
8.9 KiB
Java

package rx.exceptions;
import com.amazon.alexa.accessory.internal.util.DeviceDatabaseUtils;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import rx.annotations.Experimental;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
/* loaded from: classes12.dex */
public final class CompositeException extends RuntimeException {
private static final long serialVersionUID = 3026362227162912146L;
private Throwable cause;
private final List<Throwable> exceptions;
private final String message;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
public static final class CompositeExceptionCausalChain extends RuntimeException {
static final String MESSAGE = "Chain of Causes for CompositeException In Order Received =>";
private static final long serialVersionUID = 3875212506787802066L;
@Override // java.lang.Throwable
public String getMessage() {
return MESSAGE;
}
}
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
public static abstract class PrintStreamOrWriter {
public abstract Object lock();
public abstract void println(Object obj);
}
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
public static final class WrappedPrintStream extends PrintStreamOrWriter {
private final PrintStream printStream;
public WrappedPrintStream(PrintStream printStream) {
this.printStream = printStream;
}
@Override // rx.exceptions.CompositeException.PrintStreamOrWriter
public Object lock() {
return this.printStream;
}
@Override // rx.exceptions.CompositeException.PrintStreamOrWriter
public void println(Object obj) {
this.printStream.println(obj);
}
}
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
public static final class WrappedPrintWriter extends PrintStreamOrWriter {
private final PrintWriter printWriter;
public WrappedPrintWriter(PrintWriter printWriter) {
this.printWriter = printWriter;
}
@Override // rx.exceptions.CompositeException.PrintStreamOrWriter
public Object lock() {
return this.printWriter;
}
@Override // rx.exceptions.CompositeException.PrintStreamOrWriter
public void println(Object obj) {
this.printWriter.println(obj);
}
}
@Deprecated
public CompositeException(String str, Collection<? extends Throwable> collection) {
LinkedHashSet linkedHashSet = new LinkedHashSet();
ArrayList arrayList = new ArrayList();
if (collection != null) {
for (Throwable th : collection) {
if (th instanceof CompositeException) {
linkedHashSet.addAll(((CompositeException) th).getExceptions());
} else if (th != null) {
linkedHashSet.add(th);
} else {
linkedHashSet.add(new NullPointerException());
}
}
} else {
linkedHashSet.add(new NullPointerException());
}
arrayList.addAll(linkedHashSet);
List<Throwable> unmodifiableList = Collections.unmodifiableList(arrayList);
this.exceptions = unmodifiableList;
this.message = unmodifiableList.size() + " exceptions occurred. ";
}
private void appendStackTrace(StringBuilder sb, Throwable th, String str) {
sb.append(str);
sb.append(th);
sb.append('\n');
for (StackTraceElement stackTraceElement : th.getStackTrace()) {
sb.append("\t\tat ");
sb.append(stackTraceElement);
sb.append('\n');
}
if (th.getCause() != null) {
sb.append("\tCaused by: ");
appendStackTrace(sb, th.getCause(), "");
}
}
private List<Throwable> getListOfCauses(Throwable th) {
ArrayList arrayList = new ArrayList();
Throwable cause = th.getCause();
if (cause != null && cause != th) {
while (true) {
arrayList.add(cause);
Throwable cause2 = cause.getCause();
if (cause2 == null || cause2 == cause) {
break;
}
cause = cause.getCause();
}
}
return arrayList;
}
private Throwable getRootCause(Throwable th) {
Throwable cause = th.getCause();
if (cause == null || cause == th) {
return th;
}
while (true) {
Throwable cause2 = cause.getCause();
if (cause2 == null || cause2 == cause) {
break;
}
cause = cause.getCause();
}
return cause;
}
private void printStackTrace(PrintStreamOrWriter printStreamOrWriter) {
StringBuilder sb = new StringBuilder(128);
sb.append(this);
sb.append('\n');
for (StackTraceElement stackTraceElement : getStackTrace()) {
sb.append("\tat ");
sb.append(stackTraceElement);
sb.append('\n');
}
int i = 1;
for (Throwable th : this.exceptions) {
sb.append(" ComposedException ");
sb.append(i);
sb.append(" :\n");
appendStackTrace(sb, th, DeviceDatabaseUtils.DELIMITER);
i++;
}
synchronized (printStreamOrWriter.lock()) {
printStreamOrWriter.println(sb.toString());
}
}
@Override // java.lang.Throwable
public synchronized Throwable getCause() {
try {
if (this.cause == null) {
CompositeExceptionCausalChain compositeExceptionCausalChain = new CompositeExceptionCausalChain();
HashSet hashSet = new HashSet();
Iterator<Throwable> it2 = this.exceptions.iterator();
Throwable th = compositeExceptionCausalChain;
while (it2.hasNext()) {
Throwable next = it2.next();
if (!hashSet.contains(next)) {
hashSet.add(next);
for (Throwable th2 : getListOfCauses(next)) {
if (hashSet.contains(th2)) {
next = new RuntimeException("Duplicate found in causal chain so cropping to prevent loop ...");
} else {
hashSet.add(th2);
}
}
try {
th.initCause(next);
} catch (Throwable unused) {
}
th = getRootCause(th);
}
}
this.cause = compositeExceptionCausalChain;
}
} catch (Throwable th3) {
throw th3;
}
return this.cause;
}
public List<Throwable> getExceptions() {
return this.exceptions;
}
@Override // java.lang.Throwable
public String getMessage() {
return this.message;
}
@Override // java.lang.Throwable
public void printStackTrace(PrintStream printStream) {
printStackTrace(new WrappedPrintStream(printStream));
}
@Override // java.lang.Throwable
public void printStackTrace(PrintWriter printWriter) {
printStackTrace(new WrappedPrintWriter(printWriter));
}
@Override // java.lang.Throwable
public void printStackTrace() {
printStackTrace(System.err);
}
public CompositeException(Collection<? extends Throwable> collection) {
this(null, collection);
}
@Experimental
public CompositeException(Throwable... thArr) {
LinkedHashSet linkedHashSet = new LinkedHashSet();
ArrayList arrayList = new ArrayList();
if (thArr != null) {
for (Throwable th : thArr) {
if (th instanceof CompositeException) {
linkedHashSet.addAll(((CompositeException) th).getExceptions());
} else if (th != null) {
linkedHashSet.add(th);
} else {
linkedHashSet.add(new NullPointerException());
}
}
} else {
linkedHashSet.add(new NullPointerException());
}
arrayList.addAll(linkedHashSet);
List<Throwable> unmodifiableList = Collections.unmodifiableList(arrayList);
this.exceptions = unmodifiableList;
this.message = unmodifiableList.size() + " exceptions occurred. ";
}
}