This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
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:11:22 +0000
- Subject: Fix InetAddress.getLocalHost()
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.
We need to merge this class with Classpath, but not on gcj release
branches. This is a gcj-only maintenance patch.
Andrew.
2006-03-22 Andrew Haley <aph@redhat.com>
* java/net/InetAddress.java: Throw an UnknownHostException if
lookup fails.
Index: InetAddress.java
===================================================================
--- InetAddress.java (revision 111600)
+++ InetAddress.java (working copy)
@@ -742,6 +742,7 @@
}
catch (Exception ex)
{
+ throw new UnknownHostException(hostname);
}
}
else