Fix Java 6 compatibility issue in DnsNameResolver

Related: #3173

Motivation:

DnsNameResolver was using InetSocketAddress.getHostString() which is
only available since Java 7.

Modifications:

Use InetSocketAddress.getHostName() in lieu of getHostString() when the
current Java version is less than 7.

Result:

DnsNameResolver runs fine on Java 6.
This commit is contained in:
Trustin Lee 2014-12-06 22:31:44 +09:00
parent 7f92771496
commit 23db94f5a1

View File

@ -642,7 +642,7 @@ public class DnsNameResolver extends SimpleNameResolver<InetSocketAddress> {
@Override
protected void doResolve(InetSocketAddress unresolvedAddress, Promise<InetSocketAddress> promise) throws Exception {
final String hostname = IDN.toASCII(unresolvedAddress.getHostString());
final String hostname = IDN.toASCII(hostname(unresolvedAddress));
final int port = unresolvedAddress.getPort();
final DnsNameResolverContext ctx = new DnsNameResolverContext(this, hostname, port, promise);
@ -650,6 +650,15 @@ public class DnsNameResolver extends SimpleNameResolver<InetSocketAddress> {
ctx.resolve();
}
private static String hostname(InetSocketAddress addr) {
// InetSocketAddress.getHostString() is available since Java 7.
if (PlatformDependent.javaVersion() < 7) {
return addr.getHostName();
} else {
return addr.getHostString();
}
}
/**
* Sends a DNS query with the specified question.
*/