JDK-8066963 : Bug #7180557 still occurs
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 7u60
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: os_x
  • CPU: x86
  • Submitted: 2014-07-01
  • Updated: 2014-12-09
  • Resolved: 2014-07-03
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
 java -version
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Darwin MacBook2 13.2.0 Darwin Kernel Version 13.2.0: Thu Apr 17 23:03:13 PDT 2014; root:xnu-2422.100.13~1/RELEASE_X86_64 x86_64

A DESCRIPTION OF THE PROBLEM :
hostname:MacBook2
java version:1.7.0_60
Exception in thread "main" java.net.UnknownHostException: MacBook2: MacBook2: nodename nor servname provided, or not known
	at java.net.InetAddress.getLocalHost(InetAddress.java:1473)
	at zarea.HostNameTest.main(HostNameTest.java:18)
Caused by: java.net.UnknownHostException: MacBook2: nodename nor servname provided, or not known
	at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
	at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)
	at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293)
	at java.net.InetAddress.getLocalHost(InetAddress.java:1469)
	... 1 more


REGRESSION.  Last worked in version 6u45

ADDITIONAL REGRESSION INFORMATION: 
java full version "1.7.0_60-b19"

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached program, Its from the original bug but I have tweaked a little so it outputs the system hostname command.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
hostname:MacBook2
java version:1.6.0_65
 getHostName(): MacBook2
 www.google.com.getHostName(): www.google.com

ACTUAL -
See error messages

ERROR MESSAGES/STACK TRACES THAT OCCUR :
hostname:MacBook2
java version:1.7.0_60
Exception in thread "main" java.net.UnknownHostException: MacBook2: MacBook2: nodename nor servname provided, or not known
	at java.net.InetAddress.getLocalHost(InetAddress.java:1473)
	at zarea.HostNameTest.main(HostNameTest.java:18)
Caused by: java.net.UnknownHostException: MacBook2: nodename nor servname provided, or not known
	at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
	at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)
	at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293)
	at java.net.InetAddress.getLocalHost(InetAddress.java:1469)
	... 1 more


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class HostNameTest {

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

	private static void listHostName() throws Exception {
		// Get runtime
        java.lang.Runtime rt = java.lang.Runtime.getRuntime();
        // Start a new process: UNIX command 
        java.lang.Process p = rt.exec("hostname");
        // You can or maybe should wait for the process to complete
        p.waitFor();
        // Get process' output: its InputStream
        java.io.InputStream is = p.getInputStream();
        java.io.BufferedReader reader = new java.io.BufferedReader(new InputStreamReader(is));
        // And print each line
        String s = null;
        while ((s = reader.readLine()) != null) {
            System.out.println("hostname:" + s);
        }
        is.close();
        }
}

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

CUSTOMER SUBMITTED WORKAROUND :
Add suffix to hostname

sudo scutil --set HostName macbook2.local

hostname:macbook2.local
java version:1.7.0_60
 getHostName(): macbook2.local
 www.google.com.getHostName(): www.google.com



Comments
this fix hasn't been ported back to jdk7 (yet)
2014-07-03