Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this usage of InetAddress.getLocalHost() work okay with Java 6 but fails with Java 7 on OSX [duplicate]

It works okay for me but on OSX Mavericks for a particular customer InetAddress.getLocalHost() is failing with Java 7 although it works okay with Java 6 with the following exception

java.net.UnknownHostException: rupert: rupert: nodename nor servname provided, or not known
    at java.net.InetAddress.getLocalHost(InetAddress.java:1466)
Caused by: java.net.UnknownHostException: rupert: nodename nor servname provided, or not known
    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:894)
    at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1286)
    at java.net.InetAddress.getLocalHost(InetAddress.java:1462)

Is this by design ?

Update

Looks to be a known bug fixed in Java 8

https://bugs.openjdk.java.net/browse/JDK-7180557

like image 460
Paul Taylor Avatar asked Nov 08 '13 16:11

Paul Taylor


2 Answers

Add the {yourhostname} part of this to /etc/hosts

e.g.

127.0.0.1       localhost {yourhostname}

and the problem disappears.

like image 148
cersgde Avatar answered Oct 19 '22 14:10

cersgde


I am guessing you will find the answer here - even though that question is about Solaris, both Mac OS X and Solaris are Unix operating systems.

like image 33
Robin Green Avatar answered Oct 19 '22 13:10

Robin Green