Use InetSocketAddress.getHostName() instead of getHostString()

Related: #3478

Motivation:

DefaultNameResolver uses InetSocketAddress.getHostString() instead of
getHostName(). Because Netty uses the DefaultNameResolver by default and
getHostString() is available only since Java 7, a user cannot use Netty
on Java 6 anymore.

Modifications:

Use InetSocketAddress.getHostName() which is practically same and also
is available in Java 6.

Result:

Netty 4.1 runs on Java 6 again.
This commit is contained in:
Trustin Lee 2015-03-10 11:45:56 +09:00
parent 8c135cdd55
commit 99c40431b9

View File

@ -41,10 +41,10 @@ public class DefaultNameResolver extends SimpleNameResolver<InetSocketAddress> {
@Override
protected void doResolve(InetSocketAddress unresolvedAddress, Promise<InetSocketAddress> promise) throws Exception {
try {
promise.setSuccess(
new InetSocketAddress(
InetAddress.getByName(unresolvedAddress.getHostString()),
unresolvedAddress.getPort()));
// Note that InetSocketAddress.getHostName() will never incur a reverse lookup here,
// because an unresolved address always has a host name.
promise.setSuccess(new InetSocketAddress(
InetAddress.getByName(unresolvedAddress.getHostName()), unresolvedAddress.getPort()));
} catch (UnknownHostException e) {
promise.setFailure(e);
}