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 @Override
protected void doResolve(InetSocketAddress unresolvedAddress, Promise<InetSocketAddress> promise) throws Exception { protected void doResolve(InetSocketAddress unresolvedAddress, Promise<InetSocketAddress> promise) throws Exception {
try { try {
promise.setSuccess( // Note that InetSocketAddress.getHostName() will never incur a reverse lookup here,
new InetSocketAddress( // because an unresolved address always has a host name.
InetAddress.getByName(unresolvedAddress.getHostString()), promise.setSuccess(new InetSocketAddress(
unresolvedAddress.getPort())); InetAddress.getByName(unresolvedAddress.getHostName()), unresolvedAddress.getPort()));
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
promise.setFailure(e); promise.setFailure(e);
} }