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:
parent
97bf8a6d61
commit
216cbd9e31
@ -642,7 +642,7 @@ public class DnsNameResolver extends SimpleNameResolver<InetSocketAddress> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doResolve(InetSocketAddress unresolvedAddress, Promise<InetSocketAddress> promise) throws Exception {
|
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 int port = unresolvedAddress.getPort();
|
||||||
|
|
||||||
final DnsNameResolverContext ctx = new DnsNameResolverContext(this, hostname, port, promise);
|
final DnsNameResolverContext ctx = new DnsNameResolverContext(this, hostname, port, promise);
|
||||||
@ -650,6 +650,15 @@ public class DnsNameResolver extends SimpleNameResolver<InetSocketAddress> {
|
|||||||
ctx.resolve();
|
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.
|
* Sends a DNS query with the specified question.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user