对我来说,它可以正常工作,但在OSX Mavericks上,针对一个特定的客户端,在Java 7下InetAddress.getLocalHost()会失败,尽管在Java 6下可以正常工作,具体异常如下:
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)
这是设计上的问题吗?
更新
看起来这是Java 8中已知的一个bug。