JDK-8077819 : InetAddress.getLocalHost().getHostName() behaving differently in JDK8
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 8u40
  • Priority: P3
  • Status: Resolved
  • Resolution: Not an Issue
  • Submitted: 2015-04-15
  • Updated: 2019-01-21
  • Resolved: 2015-04-20
Related Reports
Relates :  
Description
InetAddress.getLocalHost().getHostName() is called in oraclepki.jar  to get 
the hostname. This API returns different hostnames when it is run on Java6/7 
and Java8. This difference in behavior is causing product functionality 
to break. 

The following output is from test enviroment - 

$ ./scripts/runGetHostNameUtilWithJava8.sh 
Running with Java 1.8.0_25 
Using InetAddress.getLocalHost().getHostName() the host name is: testhost 
Using InetAddress.getLocalHost().toString()    the host name is: testhost/10.10.10.10 
Stripped host using InetAddress.getLocalHost().toString() the host name is: testhost 

$ ./scripts/runGetHostNameUtilWithJava7.sh 
Running with Java 1.7 
Using InetAddress.getLocalHost().getHostName() the host name is: test.domain.com 
Using InetAddress.getLocalHost().toString()    the host name is: test.domain.com/10.10.10.10 
Stripped host using InetAddress.getLocalHost().toString() the host name is: test.domain.com 
Comments
Since: http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/81987765cb81 We call getaddrinfo / getnameinfo to get a local host name. (we supply both calls with the hostname from ::gethostname) As a result of the transition to these calls we now respect local configuration (e.g. aliases in /etc/hosts & nsswitch.conf config) JDK7s old gethostbyname_r/gethostbyaddr(_r) way of doing things checked the nameservice before local config files.
20-04-2015