Fix a bug of DnsNameResolver while working with NoopDnsCache.
Motivation: If DnsNameResolver works with NoopDnsCache, IndexOutOfBoundsException will be thrown. Modifications: Test if the result of DnsNameResolver.get(hostname) is empty before accessing it's elements.
This commit is contained in:
parent
f0a5ee068f
commit
2562ef7cbe
@ -337,7 +337,7 @@ public class DnsNameResolver extends InetNameResolver {
|
|||||||
Promise<InetAddress> promise,
|
Promise<InetAddress> promise,
|
||||||
DnsCache resolveCache) {
|
DnsCache resolveCache) {
|
||||||
final List<DnsCacheEntry> cachedEntries = resolveCache.get(hostname);
|
final List<DnsCacheEntry> cachedEntries = resolveCache.get(hostname);
|
||||||
if (cachedEntries == null) {
|
if (cachedEntries == null || cachedEntries.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -443,7 +443,7 @@ public class DnsNameResolver extends InetNameResolver {
|
|||||||
Promise<List<InetAddress>> promise,
|
Promise<List<InetAddress>> promise,
|
||||||
DnsCache resolveCache) {
|
DnsCache resolveCache) {
|
||||||
final List<DnsCacheEntry> cachedEntries = resolveCache.get(hostname);
|
final List<DnsCacheEntry> cachedEntries = resolveCache.get(hostname);
|
||||||
if (cachedEntries == null) {
|
if (cachedEntries == null || cachedEntries.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,6 +278,12 @@ public class DnsNameResolverTest {
|
|||||||
.resolvedAddressTypes(resolvedAddressTypes);
|
.resolvedAddressTypes(resolvedAddressTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static DnsNameResolverBuilder newNonCachedResolver(InternetProtocolFamily... resolvedAddressTypes) {
|
||||||
|
return newResolver()
|
||||||
|
.resolveCache(NoopDnsCache.INSTANCE)
|
||||||
|
.resolvedAddressTypes(resolvedAddressTypes);
|
||||||
|
}
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void init() throws Exception {
|
public static void init() throws Exception {
|
||||||
dnsServer.start();
|
dnsServer.start();
|
||||||
@ -349,6 +355,16 @@ public class DnsNameResolverTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNonCachedResolve() throws Exception {
|
||||||
|
DnsNameResolver resolver = newNonCachedResolver(InternetProtocolFamily.IPv4).build();
|
||||||
|
try {
|
||||||
|
testResolve0(resolver, EXCLUSIONS_RESOLVE_A);
|
||||||
|
} finally {
|
||||||
|
resolver.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static Map<String, InetAddress> testResolve0(DnsNameResolver resolver, Set<String> excludedDomains)
|
private static Map<String, InetAddress> testResolve0(DnsNameResolver resolver, Set<String> excludedDomains)
|
||||||
throws InterruptedException {
|
throws InterruptedException {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user