package s1; import android.util.Log; import com.google.android.gms.ads.RequestConfiguration; import java.io.IOException; import java.io.PrintStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; /* loaded from: classes.dex */ public final class q extends Exception { /* renamed from: g, reason: collision with root package name */ private static final StackTraceElement[] f13946g = new StackTraceElement[0]; /* renamed from: a, reason: collision with root package name */ private final List f13947a; /* renamed from: b, reason: collision with root package name */ private q1.f f13948b; /* renamed from: c, reason: collision with root package name */ private q1.a f13949c; /* renamed from: d, reason: collision with root package name */ private Class f13950d; /* renamed from: e, reason: collision with root package name */ private String f13951e; /* renamed from: f, reason: collision with root package name */ private Exception f13952f; public q(String str) { this(str, Collections.emptyList()); } private void a(Throwable th, List list) { if (!(th instanceof q)) { list.add(th); return; } Iterator it = ((q) th).e().iterator(); while (it.hasNext()) { a((Throwable) it.next(), list); } } private static void b(List list, Appendable appendable) { try { c(list, appendable); } catch (IOException e10) { throw new RuntimeException(e10); } } private static void c(List list, Appendable appendable) { int size = list.size(); int i10 = 0; while (i10 < size) { int i11 = i10 + 1; appendable.append("Cause (").append(String.valueOf(i11)).append(" of ").append(String.valueOf(size)).append("): "); Throwable th = (Throwable) list.get(i10); if (th instanceof q) { ((q) th).h(appendable); } else { d(th, appendable); } i10 = i11; } } private static void d(Throwable th, Appendable appendable) { try { appendable.append(th.getClass().toString()).append(": ").append(th.getMessage()).append('\n'); } catch (IOException unused) { throw new RuntimeException(th); } } private void h(Appendable appendable) { d(this, appendable); b(e(), new a(appendable)); } public List e() { return this.f13947a; } public List f() { ArrayList arrayList = new ArrayList(); a(this, arrayList); return arrayList; } @Override // java.lang.Throwable public Throwable fillInStackTrace() { return this; } public void g(String str) { List f10 = f(); int size = f10.size(); int i10 = 0; while (i10 < size) { StringBuilder sb = new StringBuilder(); sb.append("Root cause ("); int i11 = i10 + 1; sb.append(i11); sb.append(" of "); sb.append(size); sb.append(")"); Log.i(str, sb.toString(), (Throwable) f10.get(i10)); i10 = i11; } } @Override // java.lang.Throwable public String getMessage() { StringBuilder sb = new StringBuilder(71); sb.append(this.f13951e); Class cls = this.f13950d; String str = RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED; sb.append(cls != null ? ", " + this.f13950d : RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED); sb.append(this.f13949c != null ? ", " + this.f13949c : RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED); if (this.f13948b != null) { str = ", " + this.f13948b; } sb.append(str); List f10 = f(); if (f10.isEmpty()) { return sb.toString(); } if (f10.size() == 1) { sb.append("\nThere was 1 root cause:"); } else { sb.append("\nThere were "); sb.append(f10.size()); sb.append(" root causes:"); } for (Throwable th : f10) { sb.append('\n'); sb.append(th.getClass().getName()); sb.append('('); sb.append(th.getMessage()); sb.append(')'); } sb.append("\n call GlideException#logRootCauses(String) for more detail"); return sb.toString(); } void i(q1.f fVar, q1.a aVar) { j(fVar, aVar, null); } void j(q1.f fVar, q1.a aVar, Class cls) { this.f13948b = fVar; this.f13949c = aVar; this.f13950d = cls; } public void k(Exception exc) { this.f13952f = exc; } @Override // java.lang.Throwable public void printStackTrace() { printStackTrace(System.err); } public q(String str, Throwable th) { this(str, Collections.singletonList(th)); } @Override // java.lang.Throwable public void printStackTrace(PrintStream printStream) { h(printStream); } public q(String str, List list) { this.f13951e = str; setStackTrace(f13946g); this.f13947a = list; } @Override // java.lang.Throwable public void printStackTrace(PrintWriter printWriter) { h(printWriter); } private static final class a implements Appendable { /* renamed from: a, reason: collision with root package name */ private final Appendable f13953a; /* renamed from: b, reason: collision with root package name */ private boolean f13954b = true; a(Appendable appendable) { this.f13953a = appendable; } private CharSequence a(CharSequence charSequence) { return charSequence == null ? RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED : charSequence; } @Override // java.lang.Appendable public Appendable append(char c10) { if (this.f13954b) { this.f13954b = false; this.f13953a.append(" "); } this.f13954b = c10 == '\n'; this.f13953a.append(c10); return this; } @Override // java.lang.Appendable public Appendable append(CharSequence charSequence) { CharSequence a10 = a(charSequence); return append(a10, 0, a10.length()); } @Override // java.lang.Appendable public Appendable append(CharSequence charSequence, int i10, int i11) { CharSequence a10 = a(charSequence); boolean z10 = false; if (this.f13954b) { this.f13954b = false; this.f13953a.append(" "); } if (a10.length() > 0 && a10.charAt(i11 - 1) == '\n') { z10 = true; } this.f13954b = z10; this.f13953a.append(a10, i10, i11); return this; } } }