JDK-8194262 : jdk.net.hosts.file malfunctions on Mac OSX 10.13
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 10
  • Priority: P3
  • Status: Resolved
  • Resolution: Not an Issue
  • OS: os_x
  • Submitted: 2017-12-29
  • Updated: 2019-06-17
  • Resolved: 2019-06-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdResolved
Related Reports
Duplicate :  
Description
I can reproduce with JDK 10 build (attempted b01, b11, b21 and b37) , though there are slightly difference on test outputs. 
No such failure on other Mac 10.11.6 environment.

It looks setting jdk.net.hosts.file doesn't take effect.
Affected:
java/net/URLPermission/nstest/LookupTest.java
java/net/SocketPermission/rebind/Test.java
java/net/InetAddress/InternalNameServiceTest.java
sun/net/InetAddress/nameservice/simple/CacheTest.java
sun/net/InetAddress/nameservice/simple/DefaultCaching.java

This is output from LookupTest.java:

Connecting to http://allowedAndFound.com:50374/foo
Unexpected IOException:allowedAndFound.com
java.lang.RuntimeException: java.net.UnknownHostException: allowedAndFound.com
	at LookupTest.test(LookupTest.java:80)
	at LookupTest.main(LookupTest.java:121)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:115)
	at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.net.UnknownHostException: allowedAndFound.com
	at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:221)
	at java.base/java.net.Socket.connect(Socket.java:591)
	at java.base/java.net.Socket.connect(Socket.java:540)
	at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:182)
	at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:474)
	at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:569)
	at java.base/sun.net.www.http.HttpClient.<init>(HttpClient.java:242)
	at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:341)
	at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:362)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1242)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1210)
	at java.base/sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1065)
	at java.base/sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1063)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.AccessController.doPrivilegedWithCombiner(AccessController.java:793)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1062)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:1009)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1581)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.access$200(HttpURLConnection.java:97)
	at java.base/sun.net.www.protocol.http.HttpURLConnection$9.run(HttpURLConnection.java:1501)
	at java.base/sun.net.www.protocol.http.HttpURLConnection$9.run(HttpURLConnection.java:1499)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.AccessController.doPrivilegedWithCombiner(AccessController.java:793)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498)
	at LookupTest.test(LookupTest.java:71)
Comments
System property needs to be set on command line
17-06-2019

You can copy the hosts file in the current working directory first: @run main jdk.test.lib.FileInstaller hosts hosts @run main/othervm -Djdk.net.hosts.file=hosts Test
08-01-2018

Where possible these test should set the system property in their @run jtreg tag. This may avoid some of the issues that can arise with an effectively read-once system property value being cached, since the property will be set by the launcher.
08-01-2018

Confirmed that it indeed works if -Djdk.net.hosts.file is set in cmd.
08-01-2018

I assume it might be related to the system property being set inside the test, and somewhere inside JDK the name service is determined before it. We've seen something similar before in jdk8u. Please try to set the system property on the command line. I know the file is inside $test.src but at least you can hard code the value in an experiment first.
03-01-2018

Passed on 9 b178, 9.0.1 b11. I don't have other Mac OSX 10.13 to verify if it is reproducible on all machine with this OS version.
29-12-2017