JDK-7180557 : InetAddress.getLocalHost throws UnknownHostException on java7u5 on OSX
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 7,7u10,8
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: os_x
  • CPU: x86
  • Submitted: 2012-06-28
  • Updated: 2015-01-26
  • Resolved: 2013-10-08
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.
JDK 7 JDK 8
7u80Fixed 8 b113Fixed
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
$ java -version
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
OSX 10.7.4

$ uname -a
Darwin d9y8kt71.corp.skytide.com 11.4.0 Darwin Kernel Version 11.4.0: Mon Apr  9 19:32:15 PDT 2012; root:xnu-1699.26.8~1/RELEASE_X86_64 x86_64


EXTRA RELEVANT SYSTEM CONFIGURATION :
$ hostname
d9y8kt71.corp.skytide.com
$ hostname -f
d9y8kt71.corp.skytide.com


A DESCRIPTION OF THE PROBLEM :
Run the following test driver program on Oracle java7u5 on OSX. It throws an exception even though it should not. Note that the very same program runs fine on java6u33 on the very same OSX host and config.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the following test driver program on Oracle java7u5 on OSX.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The program should print something like d9y8kt71.corp.skytide.com

ACTUAL -
[hoschek /sky/cdnapp/build/classes] java -cp . HostNameTest
Exception in thread "main" java.net.UnknownHostException: d9y8kt71.corp.skytide.com: d9y8kt71.corp.skytide.com: nodename nor servname provided, or not known
	at java.net.InetAddress.getLocalHost(InetAddress.java:1438)
	at HostNameTest.main(HostNameTest.java:8)
Caused by: java.net.UnknownHostException: d9y8kt71.corp.skytide.com: nodename nor servname provided, or not known
	at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
	at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:866)
	at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1258)
	at java.net.InetAddress.getLocalHost(InetAddress.java:1434)
	... 1 more


ERROR MESSAGES/STACK TRACES THAT OCCUR :
See full stack trace above.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

import java.net.InetAddress;
import java.net.UnknownHostException;

public class HostNameTest {

	public static void main(String[] args) throws UnknownHostException {
		String version = System.getProperty("java.version");
		System.out.println(version + " getHostName(): " + InetAddress.getLocalHost().getHostName());
		System.out.println(version + " www.google.com.getHostName(): " + InetAddress.getByName("www.google.com").getHostName());
	}
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
We are not aware of any workaround.

Comments
No issues related to the InetAddress related fixes in the latest nightly. SQE OK to take all 5 fixes to CPU15_02: JDK-8071499, JDK-8027961, JDK-7180557, JDK-8010371, JDK-8026245
26-01-2015

I created a backport bug to for this, and assigned it to Rob. I think the change is suitable for backport as it is small, localised, and the scope if well understood. Though a hg export/import may not apply cleanly, but the conflicts should be trivial.
09-12-2014

Verified with JDK-8026245 verification result.
07-01-2014

Existing tests in the jdk regression library should be sufficient to validate this change.
14-10-2013

Currently under review on net-dev@o.j.n: http://www.mail-archive.com/net-dev@openjdk.java.net/msg07085.html
27-09-2013

It is certainly network configuration dependent. Regardless there is a fix for this issue currently under discussion on the alias for JDK8. I'm hoping to publish an updated webrev at some point next week.
06-09-2013

The comments in this bug mentioned that this issue is machine dependent and can be reproduced if the hostname does not include a domainname. The customer replied to these comments saying that his hostname include domainname. He does not believe this is machine dependent as he sees this in 3 different machines. His results are: Machine 10.8.4 OS Java 6 DHCP IP --> Works Java 6 FIXED IP --> Works Java 7 DHCP IP --> DOES NOT Work Java 7 FIXED IP --> Works To the customer, the problem is isolated to Java 7 DHCP IP. Can you verify this?
06-09-2013

I attached the customer's testcase to this bug, getHostName.jar. The customer said within the same machine, if he changes the Fixed IP address it works. When he changes it to DHCP, it fails. It is very easy to duplication the issue if you try it in Mac OS 10.8. with Java 7u25, it fails. But if you try it with Java 6u37, it works.
13-08-2013

I think the main thing here is to get access to a system where this can be reproduced. All the systems that we've looked at to date have been issues specific to those machine configurations.
13-08-2013

This bug has impact also on NetBeans: https://netbeans.org/bugzilla/show_bug.cgi?id=234040 http://statistics.netbeans.org/analytics/exception.do?id=684996 Can it be fixed in nearest 7uX and 8? Thanks.
07-08-2013

This is reported to be affecting test runs on MacOSX outside Oracle
30-07-2013

The BSD port added code to use getaddrinfo to get the local host name and lookup the address so this mean that InetAddress is using given calls than previous releases.
12-12-2012

This might be a good time to get Apple involved, since it works fine on 6u37. I don't know if the Java portion of the code changed significantly between 6 and 7, but the native implementation might be different enough to warrant a comparison.
12-12-2012

I just confirmed - this looks like a problem (with or without -Djava.net.preferIPv4Stack=true). The given test case actually works fine when using the Oracle internal VPN, but is giving the exception otherwise. Further investigation is required. I also observed that InetAddress.getByName("www.google.com").getHostName()) works fine eitherway, it is InetAddress.getLocalHost().getHostName()) that is throwing an exception. The problem occurs with jdk8 as well.
12-12-2012

Can you post your results from running with IPv6 disabled (-Djava.net.preferIPv4Stack=true).
12-12-2012

Bumped to p3. It's a regression from Apple's JDK 6 -- the same test worked for me in Apple's 6u37.
12-12-2012

Reopening this because I was able to reproduce with 7u10 and 10.8.2. This was requested to be escalated by FileMaker. I am able to reproduce this with the included test case, but only when NOT on VPN or on Oracle's network. [skovatch:~/src/miscCode] $ java HostNameTest Exception in thread "main" java.net.UnknownHostException: indians: indians: nodename nor servname provided, or not known at java.net.InetAddress.getLocalHost(InetAddress.java:1438) at HostNameTest.main(HostNameTest.java:8) Caused by: java.net.UnknownHostException: indians: nodename nor servname provided, or not known at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:866) at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1258) at java.net.InetAddress.getLocalHost(InetAddress.java:1434) ... 1 more
12-12-2012

Couldn't reproduce, neither can the requester anymore: "For some reason I am nomore able to reproduce the issue here. Everything is working fine now. It looks like this was a just a transient networking issue after all, and jdk6 appears to have reacted to it in a more graceful way than jdk7. I'm ok with closing the bug database issue (can't repro)."
03-10-2012