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,
|
||||
DnsCache resolveCache) {
|
||||
final List<DnsCacheEntry> cachedEntries = resolveCache.get(hostname);
|
||||
if (cachedEntries == null) {
|
||||
if (cachedEntries == null || cachedEntries.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -443,7 +443,7 @@ public class DnsNameResolver extends InetNameResolver {
|
||||
Promise<List<InetAddress>> promise,
|
||||
DnsCache resolveCache) {
|
||||
final List<DnsCacheEntry> cachedEntries = resolveCache.get(hostname);
|
||||
if (cachedEntries == null) {
|
||||
if (cachedEntries == null || cachedEntries.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -278,6 +278,12 @@ public class DnsNameResolverTest {
|
||||
.resolvedAddressTypes(resolvedAddressTypes);
|
||||
}
|
||||
|
||||
private static DnsNameResolverBuilder newNonCachedResolver(InternetProtocolFamily... resolvedAddressTypes) {
|
||||
return newResolver()
|
||||
.resolveCache(NoopDnsCache.INSTANCE)
|
||||
.resolvedAddressTypes(resolvedAddressTypes);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws Exception {
|
||||
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)
|
||||
throws InterruptedException {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user