discord-jadx/app/src/main/java/rx/exceptions/CompositeException.java

231 lines
7.5 KiB
Java
Raw Normal View History

2021-06-27 20:44:35 +00:00
package rx.exceptions;
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;
2022-03-02 20:59:20 +00:00
/* loaded from: classes3.dex */
2021-06-27 20:44:35 +00:00
public final class CompositeException extends RuntimeException {
private static final long serialVersionUID = 3026362227162912146L;
private Throwable cause;
private final List<Throwable> exceptions;
private final String message;
2022-03-02 20:59:20 +00:00
/* loaded from: classes3.dex */
2021-06-27 20:44:35 +00:00
public static final class a extends RuntimeException {
private static final long serialVersionUID = 3875212506787802066L;
@Override // java.lang.Throwable
public String getMessage() {
return "Chain of Causes for CompositeException In Order Received =>";
}
}
2022-03-02 20:59:20 +00:00
/* loaded from: classes3.dex */
2021-06-27 20:44:35 +00:00
public static abstract class b {
public abstract Object a();
public abstract void b(Object obj);
}
2022-03-02 20:59:20 +00:00
/* loaded from: classes3.dex */
2021-06-27 20:44:35 +00:00
public static final class c extends b {
public final PrintStream a;
public c(PrintStream printStream) {
this.a = printStream;
}
@Override // rx.exceptions.CompositeException.b
public Object a() {
return this.a;
}
@Override // rx.exceptions.CompositeException.b
public void b(Object obj) {
this.a.println(obj);
}
}
2022-03-02 20:59:20 +00:00
/* loaded from: classes3.dex */
2021-06-27 20:44:35 +00:00
public static final class d extends b {
public final PrintWriter a;
public d(PrintWriter printWriter) {
this.a = printWriter;
}
@Override // rx.exceptions.CompositeException.b
public Object a() {
return this.a;
}
@Override // rx.exceptions.CompositeException.b
public void b(Object obj) {
this.a.println(obj);
}
}
public CompositeException(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).exceptions);
} 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. ";
}
public CompositeException(Throwable... thArr) {
2022-03-02 20:59:20 +00:00
List<Throwable> unmodifiableList;
2021-06-27 20:44:35 +00:00
LinkedHashSet linkedHashSet = new LinkedHashSet();
ArrayList arrayList = new ArrayList();
for (Throwable th : thArr) {
if (th instanceof CompositeException) {
linkedHashSet.addAll(((CompositeException) th).exceptions);
} else if (th != null) {
linkedHashSet.add(th);
} else {
linkedHashSet.add(new NullPointerException());
}
}
arrayList.addAll(linkedHashSet);
2022-03-02 20:59:20 +00:00
this.exceptions = Collections.unmodifiableList(arrayList);
2021-06-27 20:44:35 +00:00
this.message = unmodifiableList.size() + " exceptions occurred. ";
}
public final void a(StringBuilder sb, Throwable th, String str) {
2022-03-02 20:59:20 +00:00
StackTraceElement[] stackTrace;
2021-06-27 20:44:35 +00:00
sb.append(str);
sb.append(th);
sb.append('\n');
2022-03-02 20:59:20 +00:00
for (StackTraceElement stackTraceElement : th.getStackTrace()) {
2021-06-27 20:44:35 +00:00
sb.append("\t\tat ");
sb.append(stackTraceElement);
sb.append('\n');
}
if (th.getCause() != null) {
sb.append("\tCaused by: ");
a(sb, th.getCause(), "");
}
}
public List<Throwable> b() {
return this.exceptions;
}
public final void c(b bVar) {
2022-03-02 20:59:20 +00:00
StackTraceElement[] stackTrace;
2021-06-27 20:44:35 +00:00
StringBuilder sb = new StringBuilder(128);
sb.append(this);
sb.append('\n');
2022-03-02 20:59:20 +00:00
for (StackTraceElement stackTraceElement : getStackTrace()) {
2021-06-27 20:44:35 +00:00
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");
a(sb, th, "\t");
i++;
}
synchronized (bVar.a()) {
bVar.b(sb.toString());
}
}
@Override // java.lang.Throwable
public synchronized Throwable getCause() {
if (this.cause == null) {
a aVar = new a();
HashSet hashSet = new HashSet();
Iterator<Throwable> it = this.exceptions.iterator();
Throwable th = aVar;
while (it.hasNext()) {
Throwable next = it.next();
if (!hashSet.contains(next)) {
hashSet.add(next);
ArrayList arrayList = new ArrayList();
Throwable cause = next.getCause();
2022-03-02 20:59:20 +00:00
if (cause != null && cause != next) {
while (true) {
arrayList.add(cause);
Throwable cause2 = cause.getCause();
if (cause2 == null || cause2 == cause) {
break;
2021-06-27 20:44:35 +00:00
}
2022-03-02 20:59:20 +00:00
cause = cause.getCause();
2021-06-27 20:44:35 +00:00
}
}
Iterator it2 = arrayList.iterator();
while (it2.hasNext()) {
Throwable th2 = (Throwable) it2.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) {
}
Throwable cause3 = th.getCause();
if (!(cause3 == null || cause3 == th)) {
while (true) {
Throwable cause4 = cause3.getCause();
if (cause4 == null || cause4 == cause3) {
break;
}
cause3 = cause3.getCause();
}
th = cause3;
}
}
}
this.cause = aVar;
}
return this.cause;
}
@Override // java.lang.Throwable
public String getMessage() {
return this.message;
}
@Override // java.lang.Throwable
public void printStackTrace() {
printStackTrace(System.err);
}
@Override // java.lang.Throwable
public void printStackTrace(PrintStream printStream) {
c(new c(printStream));
}
@Override // java.lang.Throwable
public void printStackTrace(PrintWriter printWriter) {
c(new d(printWriter));
}
}