mirror of
https://github.com/square/okhttp.git
synced 2025-07-31 05:04:26 +03:00
Use Throwable.addSuppressed directly
This is available with the new minimum requirements.
This commit is contained in:
@ -34,7 +34,6 @@ import okhttp3.Request;
|
|||||||
import okhttp3.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
import okhttp3.internal.Util;
|
|
||||||
import okhttp3.internal.platform.Platform;
|
import okhttp3.internal.platform.Platform;
|
||||||
import okhttp3.internal.publicsuffix.PublicSuffixDatabase;
|
import okhttp3.internal.publicsuffix.PublicSuffixDatabase;
|
||||||
import okio.ByteString;
|
import okio.ByteString;
|
||||||
@ -222,7 +221,7 @@ public class DnsOverHttps implements Dns {
|
|||||||
unknownHostException.initCause(failure);
|
unknownHostException.initCause(failure);
|
||||||
|
|
||||||
for (int i = 1; i < failures.size(); i++) {
|
for (int i = 1; i < failures.size(); i++) {
|
||||||
Util.addSuppressedIfPossible(unknownHostException, failures.get(i));
|
unknownHostException.addSuppressed(failures.get(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
throw unknownHostException;
|
throw unknownHostException;
|
||||||
|
@ -18,8 +18,6 @@ package okhttp3.internal;
|
|||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InterruptedIOException;
|
import java.io.InterruptedIOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.net.IDN;
|
import java.net.IDN;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
@ -90,27 +88,6 @@ public final class Util {
|
|||||||
|
|
||||||
public static final Comparator<String> NATURAL_ORDER = String::compareTo;
|
public static final Comparator<String> 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
|
* Quick and dirty pattern to differentiate IP addresses from hostnames. This is an approximation
|
||||||
* of Android's private InetAddress#isNumeric API.
|
* of Android's private InetAddress#isNumeric API.
|
||||||
|
@ -17,8 +17,6 @@ package okhttp3.internal.connection;
|
|||||||
|
|
||||||
import java.io.IOException;
|
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
|
* 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.
|
* 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) {
|
void addConnectException(IOException e) {
|
||||||
addSuppressedIfPossible(firstException, e);
|
firstException.addSuppressed(e);
|
||||||
lastException = e;
|
lastException = e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user