package com.bumptech.glide.load.engine; 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; import o.InterfaceC2545agd; import o.pNW; /* loaded from: classes.dex */ public final class GlideException extends Exception { private static final StackTraceElement[] a = new StackTraceElement[0]; public pNW b; public InterfaceC2545agd c; private final List d; public Class e; private String g; @Override // java.lang.Throwable public final Throwable fillInStackTrace() { return this; } public GlideException(String str) { this(str, (List) Collections.emptyList()); } public GlideException(String str, Throwable th) { this(str, (List) Collections.singletonList(th)); } public GlideException(String str, List list) { this.g = str; setStackTrace(a); this.d = list; } public final void a(Throwable th, List list) { if (th instanceof GlideException) { Iterator it = ((GlideException) th).d.iterator(); while (it.hasNext()) { a(it.next(), list); } return; } list.add(th); } @Override // java.lang.Throwable public final void printStackTrace() { printStackTrace(System.err); } @Override // java.lang.Throwable public final String getMessage() { String str; String str2; StringBuilder sb = new StringBuilder(71); sb.append(this.g); String str3 = ""; if (this.e != null) { StringBuilder sb2 = new StringBuilder(", "); sb2.append(this.e); str = sb2.toString(); } else { str = ""; } sb.append(str); if (this.b != null) { StringBuilder sb3 = new StringBuilder(", "); sb3.append(this.b); str2 = sb3.toString(); } else { str2 = ""; } sb.append(str2); if (this.c != null) { StringBuilder sb4 = new StringBuilder(", "); sb4.append(this.c); str3 = sb4.toString(); } sb.append(str3); ArrayList arrayList = new ArrayList(); a(this, arrayList); if (arrayList.isEmpty()) { return sb.toString(); } if (arrayList.size() == 1) { sb.append("\nThere was 1 root cause:"); } else { sb.append("\nThere were "); sb.append(arrayList.size()); sb.append(" root causes:"); } for (Throwable th : arrayList) { 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(); } private static void c(Throwable th, Appendable appendable) { try { appendable.append(th.getClass().toString()).append(": ").append(th.getMessage()).append('\n'); } catch (IOException unused) { throw new RuntimeException(th); } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public static final class IeS implements Appendable { private final Appendable b; private boolean d = true; IeS(Appendable appendable) { this.b = appendable; } @Override // java.lang.Appendable public final Appendable append(char c) throws IOException { if (this.d) { this.d = false; this.b.append(" "); } this.d = c == '\n'; this.b.append(c); return this; } @Override // java.lang.Appendable public final Appendable append(CharSequence charSequence) throws IOException { if (charSequence == null) { charSequence = ""; } return append(charSequence, 0, charSequence.length()); } @Override // java.lang.Appendable public final Appendable append(CharSequence charSequence, int i, int i2) throws IOException { if (charSequence == null) { charSequence = ""; } boolean z = false; if (this.d) { this.d = false; this.b.append(" "); } if (charSequence.length() > 0 && charSequence.charAt(i2 - 1) == '\n') { z = true; } this.d = z; this.b.append(charSequence, i, i2); return this; } } private static void d(List list, Appendable appendable) { try { int size = list.size(); int i = 0; while (i < size) { int i2 = i + 1; appendable.append("Cause (").append(String.valueOf(i2)).append(" of ").append(String.valueOf(size)).append("): "); Throwable th = list.get(i); if (th instanceof GlideException) { GlideException glideException = (GlideException) th; c(glideException, appendable); d(glideException.d, new IeS(appendable)); } else { c(th, appendable); } i = i2; } } catch (IOException e) { throw new RuntimeException(e); } } @Override // java.lang.Throwable public final void printStackTrace(PrintStream printStream) { c(this, printStream); d(this.d, new IeS(printStream)); } @Override // java.lang.Throwable public final void printStackTrace(PrintWriter printWriter) { c(this, printWriter); d(this.d, new IeS(printWriter)); } }