United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7180557 InetAddress.getLocalHost throws UnknownHostException on java7u5 on OSX
JDK-7180557 : InetAddress.getLocalHost throws UnknownHostException on java7u5 on OSX

Details
Type:
Bug
Submit Date:
2012-06-28
Status:
Closed
Updated Date:
2014-07-03
Project Name:
JDK
Resolved Date:
2013-10-08
Component:
core-libs
OS:
os_x
Sub-Component:
java.net
CPU:
x86
Priority:
P2
Resolution:
Fixed
Affected Versions:
7,7u10,8
Fixed Versions:

Related Reports
Relates:

Sub Tasks

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
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

                                     
2012-12-12
Bumped to p3. It's a regression from Apple's JDK 6 -- the same test worked for me in Apple's 6u37.
                                     
2012-12-12
Can you post your results from running with IPv6 disabled (-Djava.net.preferIPv4Stack=true). 
                                     
2012-12-12
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)."

                                     
2012-10-03
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.
                                     
2012-12-12
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. 
                                     
2012-12-12
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.

                                     
2012-12-12
This is reported to be affecting test runs on MacOSX outside Oracle
                                     
2013-07-30
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.
                                     
2013-08-07
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.
                                     
2013-08-13
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.
                                     
2013-08-13
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?
                                     
2013-09-06
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.
                                     
2013-09-06
Currently under review on net-dev@o.j.n:
  http://www.mail-archive.com/net-dev@openjdk.java.net/msg07085.html
                                     
2013-09-27
URL:   http://hg.openjdk.java.net/jdk8/tl/jdk/rev/f1e31376f419
User:  robm
Date:  2013-10-08 23:13:22 +0000

                                     
2013-10-08
Existing tests in the jdk regression library should be sufficient to validate this change.
                                     
2013-10-14
URL:   http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/f1e31376f419
User:  lana
Date:  2013-10-22 17:23:08 +0000

                                     
2013-10-22
Verified with JDK-8026245 verification result.
                                     
2014-01-07



Hardware and Software, Engineered to Work Together