This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Fix InetAddress.getLocalHost()


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]