This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Fix InetAddress.getLocalHost()
- From: Andrew Haley <aph at redhat dot com>
- To: java at gcc dot gnu dot org
- Date: Wed, 22 Mar 2006 20:15:21 +0000
- Subject: Re: Fix InetAddress.getLocalHost()
- References: <17441.44906.483483.355347@zapata.pink>
Andrew Haley writes:
> Consider this case:
>
> import java.net.*;
>
> public class oops
> {
> static byte[] getIPAddress()
> throws UnknownHostException
> {
> return InetAddress.getLocalHost().getAddress();
> }
>
> public static void main(String[] argv)
> throws UnknownHostException
> {
> getIPAddress();
> }
> }
>
> Now, imagine we don't have reverse lookup working for this machine's
> name, perhaps because we have no net connection. This is common with
> laptops.
>
> At the moment we get a NullPointerException from getAddress(), but
> other JVMs do:
>
> $ java oops
> Exception in thread "main" java.net.UnknownHostException: zorro.pink: zorro.pink
> at java.net.InetAddress.getLocalHost(InetAddress.java:1279)
> at oops.getIPAddress(oops.java:8)
> at oops.main(oops.java:14)
>
> This causes failures on JOnAS and on Eclipse.
Sorry, that was rather ambiguous. I meant to say that throwing a
NullPointerException instead of a UnknownHostException causes failures
on JOnAS and on Eclipse.
Andrew.