--- old/src/java.base/share/classes/java/net/InetAddress.java 2016-03-18 11:10:30.682068072 +0000 +++ new/src/java.base/share/classes/java/net/InetAddress.java 2016-03-18 11:10:30.534071253 +0000 @@ -281,7 +281,7 @@ } /* Used to store the name service provider */ - private static transient NameService nameService = null; + private static NameService nameService = null; /* Used to store the best available hostname */ private transient String canonicalHostName = null; @@ -857,93 +857,90 @@ /** * NameService provides host and address lookup service - * + * + * @since 9 */ private interface NameService { /** - * Lookup a host mapping by name. Retrieve the IP addresses - * associated with a host - * + * Looks up a host mapping by name. Retrieves the IP addresses + * associated with a host. + * * @param host the specified hostname - * @return array of IP addresses for the requested host + * @return an array of IP addresses for the given host name * @throws UnknownHostException - * if no IP address for the {@code host} could be found + * if no IP address for the {@code host} could be found */ InetAddress[] lookupAllHostAddr(String host) - throws UnknownHostException; + throws UnknownHostException; /** - * Lookup the host corresponding to the IP address provided - * + * Looks up the host corresponding to the given IP address. + * * @param addr byte array representing an IP address * @return {@code String} representing the host name mapping * @throws UnknownHostException - * if no host found for the specified IP address + * if no host found for the specified IP address */ String getHostByAddr(byte[] addr) throws UnknownHostException; - } /** * The default NameService implementation, which delegates to the underlying * OS network libraries to resolve host address mappings. - * + * + * @since 9 */ private static final class PlatformNameService implements NameService { public InetAddress[] lookupAllHostAddr(String host) - throws UnknownHostException { - + throws UnknownHostException + { return impl.lookupAllHostAddr(host); - } public String getHostByAddr(byte[] addr) throws UnknownHostException { - return impl.getHostByAddr(addr); - } - } /** - *
The HostsFileNameService provides host address mapping - * by reading the entries in a hosts file, which is specified in the - * property jdk.net.hosts.file + * A HostsFileNameService provides host address mappings by reading the + * entries in a hosts file, which is specified by the {@code + * jdk.net.hosts.file} system property. * - *
The file format is that which corresponds with the /etc/hosts file - * ipaddress host alias list + *
The file format is that which corresponds to the /etc/hosts file + * IP Address host alias list. * - *
When the file lookup is enabled it replaces the call flows to the native - * OS ip nameservice lookup calls + *
When the file lookup is enabled it replaces the default NameService + * implementation. * - *
This functionalty doesn't currently support IPV6 mappings - * This can be provided whenever it is required + * @since 9 */ private static final class HostsFileNameService implements NameService { private final String hostsFile; - + public HostsFileNameService (String hostsFileName) { - this.hostsFile = hostsFileName; + this.hostsFile = hostsFileName; } - private String addrToString(byte addr[]) { + private String addrToString(byte addr[]) { return Byte.toString(addr[0]) + "." + Byte.toString(addr[1]) + "." + Byte.toString(addr[2]) + "." + Byte.toString(addr[3]); } /** - * Lookup the host name corresponding to the IP address provided. - * Search the configured host file a host name corresponding to + * Looks up the host name corresponding to the IP address provided. + * Searches the configured host file for a host name corresponding to * the specified IP address. * * @param addr byte array representing an IP address * @return {@code String} representing the host name mapping * @throws UnknownHostException - * if no host found for the specified IP address + * if no host found for the specified IP address */ + @Override public String getHostByAddr(byte[] addr) throws UnknownHostException { String hostEntry; String host = null; @@ -979,23 +976,24 @@ /** - *
Lookup a host mapping by name. Retrieve the IP addresses + * Looks up a host mapping by name. Retrieves the IP addresses * associated with a host. * - *
Search the configured hosts file for the addresses assocaited with - * with the specified host name. + *
Searches the configured hosts file for the addresses associated
+ * with with the specified host name.
*
* @param host the specified hostname
* @return array of IP addresses for the requested host
* @throws UnknownHostException
* if no IP address for the {@code host} could be found
*/
-
+ @Override
public InetAddress[] lookupAllHostAddr(String host)
- throws UnknownHostException {
+ throws UnknownHostException
+ {
String hostEntry;
- String addrStr = null;
- InetAddress[] res = null;
+ String addrStr;
+ InetAddress[] res;
byte addr[] = new byte[4];
ArrayList The default NameService is the PlatformNameService, which typically
+ * delegates name and address resolution calls to the underlying OS network
+ * libraries.
+ *
+ * A HostsFileNameService is created if the {@code jdk.net.hosts.file}
+ * system property is set. If the specified file doesn't exist, the name or
+ * address lookup will result in an UnknownHostException. Thus, non existent
+ * hosts file is handled as if the file is empty.
*
- * The default NameService is the PlatformNameService, which typically
- * delegates name and address resolution calls to the underlying
- * OS network libraries.
- *
- * If jdk.net.hosts.file is set, and the file exists then
- * instantiate a HostsFileNameService
- * else
- * instantiate a PlatformNameService.
- *
- * @return the instantiated {@code NameService}
+ * @return a NameService
*/
private static NameService createNameService() {
-
String hostsFileName = AccessController
.doPrivileged(new GetPropertyAction("jdk.net.hosts.file"));
- NameService theNameService;
+
if (hostsFileName != null) {
- theNameService = new HostsFileNameService(hostsFileName);
+ return new HostsFileNameService(hostsFileName);
} else {
- theNameService = new PlatformNameService();
+ return new PlatformNameService();
}
- return theNameService;
}
/**