InetAddress.getLocalHost () permission on OSX Lion offline

Are there problems with Java resolution InetAddress.getLocalHost () in Java with OSX Lion when working offline (i.e. not connected to the Internet)?

It looks like localhost: 127.0.0.1 is not allowed at all:

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

Nothing special in my / 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 

I suspect that this is not a Java problem, but an OSX Lion DNS resolution issue.

Can anyone help?

If this is not the right forum, where can I ask about it?

Any tips on how to debug this further at OSX level?

UPDATE 10/26/2011 - This may be a JDK error, the following test:

 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); } 

In offline mode, the following will be printed:

 With reverse lookup: localhost/127.0.0.1 

Cheers, Galder

+4
source share
1 answer

Found a workaround for this problem, just add an alias for localhost in the network interface:

 sudo ifconfig en0 alias 127.0.0.1 

As soon as this happens, I no longer get any problems with localhost with offline access.

+7
source

All Articles