[Patch] PR 17069: fix for InetAddress.getLocalHost

Michael Koch konqueror@gmx.de
Sun Jan 9 14:42:00 GMT 2005


Hi list,


I wrote the attached patch to fix PR libgcj/17069. The problem was that
InetAddress.getLocalHost() returned an invalid InetAddress object when
the local hostname could not be determined (e.g. when /etc/hostname
doesn't exist or is not setup properly).

Ok to commit to trunk ?


Michael

2005-01-09  Michael Koch  <konqueror@gmx.de>

	PR libgcj/17069
	* java/net/InetAddress.java (getLocalHost):
	Throw UnknownHostException if local hostname cannot be determined.

-------------- next part --------------
Index: java/net/InetAddress.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/InetAddress.java,v
retrieving revision 1.34
diff -u -r1.34 InetAddress.java
--- java/net/InetAddress.java	17 Nov 2004 07:09:57 -0000	1.34
+++ java/net/InetAddress.java	9 Jan 2005 14:38:41 -0000
@@ -714,7 +714,7 @@
 	  }
       }
     
-    if (hostname != null)
+    if (hostname != null && hostname.length() != 0)
       {
 	try
 	  {
@@ -725,6 +725,8 @@
 	  {
 	  }
       }
+    else
+      throw new UnknownHostException();
     
     if (localhost == null)
       localhost = new InetAddress (loopbackAddress, "localhost");


More information about the Java-patches mailing list