Is anyone having issues with Java's InetAddress.getLocalHost() resolution in Java with OSX Lion when working offline (i.e. not connected to internet)?
It would appear that localhost:127.0.0.1 is not resolved 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 this is not a Java issue, but rather an OSX Lion DNS resolution issue.
Can anyone help?
If this is not the right forum, where can I ask about this?
Any tips on how debug this further at OSX level?
UPDATE 26/10/2011 - This could be JDK bug, 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);
}
Would print the following when offline:
With reverse lookup: localhost/127.0.0.1
Cheers, Galder
Found a way to workaround this issue, just add an alias for localhost to the network interface:
sudo ifconfig en0 alias 127.0.0.1
Once that's in place, I get no localhost issues any more when offline.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With