离线时OSX Lion上的InetAddress.getLocalHost()解析

在离线工作(即没有连接到互联网)时,是否有任何人在使用OSX Lion的Java中解决Java的InetAddress.getLocalHost()问题?

似乎localhost:127.0.0.1根本没有解决:

Caused by: java.lang.ArrayIndexOutOfBoundsException: 0 at java.net.InetAddress.getLocalHost(InetAddress.java:1356) 

我的/ etc / hosts没什么特别之处:

 ## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost 

我怀疑这不是Java问题,而是OSX Lion DNS解决问题。

有人可以帮忙吗?

如果这不是正确的论坛,我可以在哪里询问这个问题?

有关如何在OSX级别进一步调试的任何提示?

更新26/10/2011 – 这可能是JDK bug,以下测试:

 InetAddress addr; try { addr = InetAddress.getLocalHost(); System.out.println("With localhost access: " + addr); } catch (ArrayIndexOutOfBoundsException e) { addr = InetAddress.getByName(null); System.out.println("With reverse lookup: " + addr); } 

离线时会打印以下内容:

 With reverse lookup: localhost/127.0.0.1 

干杯,高尔德

找到解决此问题的方法,只需将localhost的别名添加到网络接口:

 sudo ifconfig en0 alias 127.0.0.1 

一旦到位,我在离线时不再遇到本地主机问题。