summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChiachang Wang <chiachangwang@google.com>2019-07-05 15:18:10 +0800
committerChiachang Wang <chiachangwang@google.com>2019-07-05 18:12:48 +0800
commit37607cbb5617e9914d76515c56c73616a86eeb46 (patch)
treea26d7c43be727b4cc6454030fa49777c1c9bfa25
parentd53f5498850e2371843dfbba2bcaad7dd5cd74a3 (diff)
Use UnknownHostException directly without casting it
ExecutionException cannot be casted to UnknownHostException. If an unresolvable dns server is set, the ExecutionException will be triggered and cause cast exception. Bug: 123435238 Test: atest com.android.server.connectivity.NetworkMonitorTest Test: Manual test with setting an unresolvable hostname in private dns config Change-Id: Icdbc33ddd03740043cac2eff7dec209ffb500e2a
-rw-r--r--src/com/android/networkstack/util/DnsUtils.java13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/com/android/networkstack/util/DnsUtils.java b/src/com/android/networkstack/util/DnsUtils.java
index e68976a..2ea5ed8 100644
--- a/src/com/android/networkstack/util/DnsUtils.java
+++ b/src/com/android/networkstack/util/DnsUtils.java
@@ -80,7 +80,7 @@ public class DnsUtils {
if (result.size() == 0) {
logger.log("FAIL: " + errorMsg.toString());
- throw new UnknownHostException(errorMsg.toString());
+ throw new UnknownHostException(host);
}
logger.log("OK: " + host + " " + result.toString());
return result.toArray(new InetAddress[0]);
@@ -134,20 +134,19 @@ public class DnsUtils {
TrafficStats.setThreadStatsTag(oldTag);
+ String errorMsg = null;
List<InetAddress> result = null;
- Exception exception = null;
try {
result = resultRef.get(timeoutMs, TimeUnit.MILLISECONDS);
} catch (ExecutionException e) {
- exception = e;
+ errorMsg = e.getMessage();
} catch (TimeoutException | InterruptedException e) {
- exception = new UnknownHostException("Timeout");
+ errorMsg = "Timeout";
} finally {
- logDnsResult(result, watch.stop() /* latency */, logger, type,
- exception != null ? exception.getMessage() : "" /* errorMsg */);
+ logDnsResult(result, watch.stop() /* latency */, logger, type, errorMsg);
}
- if (null != exception) throw (UnknownHostException) exception;
+ if (null != errorMsg) throw new UnknownHostException(host);
return result.toArray(new InetAddress[0]);
}