diff --git a/okhttp-dnsoverhttps/src/main/java/okhttp3/dnsoverhttps/DnsOverHttps.java b/okhttp-dnsoverhttps/src/main/java/okhttp3/dnsoverhttps/DnsOverHttps.java index df56442f4..fb6901fe3 100644 --- a/okhttp-dnsoverhttps/src/main/java/okhttp3/dnsoverhttps/DnsOverHttps.java +++ b/okhttp-dnsoverhttps/src/main/java/okhttp3/dnsoverhttps/DnsOverHttps.java @@ -34,7 +34,6 @@ import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; import okhttp3.ResponseBody; -import okhttp3.internal.Util; import okhttp3.internal.platform.Platform; import okhttp3.internal.publicsuffix.PublicSuffixDatabase; import okio.ByteString; @@ -222,7 +221,7 @@ public class DnsOverHttps implements Dns { unknownHostException.initCause(failure); for (int i = 1; i < failures.size(); i++) { - Util.addSuppressedIfPossible(unknownHostException, failures.get(i)); + unknownHostException.addSuppressed(failures.get(i)); } throw unknownHostException; diff --git a/okhttp/src/main/java/okhttp3/internal/Util.java b/okhttp/src/main/java/okhttp3/internal/Util.java index 2f535c139..a1d07269a 100644 --- a/okhttp/src/main/java/okhttp3/internal/Util.java +++ b/okhttp/src/main/java/okhttp3/internal/Util.java @@ -18,8 +18,6 @@ package okhttp3.internal; import java.io.Closeable; import java.io.IOException; import java.io.InterruptedIOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.net.IDN; import java.net.InetAddress; import java.net.ServerSocket; @@ -90,27 +88,6 @@ public final class Util { public static final Comparator NATURAL_ORDER = String::compareTo; - private static final Method addSuppressedExceptionMethod; - - static { - Method m; - try { - m = Throwable.class.getDeclaredMethod("addSuppressed", Throwable.class); - } catch (Exception e) { - m = null; - } - addSuppressedExceptionMethod = m; - } - - public static void addSuppressedIfPossible(Throwable e, Throwable suppressed) { - if (addSuppressedExceptionMethod != null) { - try { - addSuppressedExceptionMethod.invoke(e, suppressed); - } catch (InvocationTargetException | IllegalAccessException ignored) { - } - } - } - /** * Quick and dirty pattern to differentiate IP addresses from hostnames. This is an approximation * of Android's private InetAddress#isNumeric API. diff --git a/okhttp/src/main/java/okhttp3/internal/connection/RouteException.java b/okhttp/src/main/java/okhttp3/internal/connection/RouteException.java index f6206f7f0..35d3af123 100644 --- a/okhttp/src/main/java/okhttp3/internal/connection/RouteException.java +++ b/okhttp/src/main/java/okhttp3/internal/connection/RouteException.java @@ -17,8 +17,6 @@ package okhttp3.internal.connection; import java.io.IOException; -import static okhttp3.internal.Util.addSuppressedIfPossible; - /** * An exception thrown to indicate a problem connecting via a single Route. Multiple attempts may * have been made with alternative protocols, none of which were successful. @@ -42,7 +40,7 @@ public final class RouteException extends RuntimeException { } void addConnectException(IOException e) { - addSuppressedIfPossible(firstException, e); + firstException.addSuppressed(e); lastException = e; } }