[kaffe] java.net.Socket#getLocalAddress() should return anylocal if not bound

Noa Resare noa at resare.com
Tue Sep 14 01:26:25 PDT 2004


On tis, 2004-09-14 at 16:34 +0900, Ito Kazumitsu wrote:
> Hi,
> 
> While running Jetty 4.2.20 with kaffe
> (ChangeLog head   : 2004-09-06  Dalibor Topic),  I found a
> case where an unexpected NullPointerException is thrown.
> And I have found a possible bug in java.net.Socket.
> 
> Sun's API document says about java.net.Socket#getLocalAddress():
> 
>     Returns:
>         the local address to which the socket is bound or
>         InetAddress.anyLocalAddress() if the socket is not bound yet.
> 
> I am afraid InetAddress.anyLocalAddress() is not defined anywhere,
> but I suppose it means anylocal or wildcard address.

> So I fixed java/net/Socket.java and found Jetty worked without problem.
> 
> --- libraries/javalib/java/net/Socket.java.orig	Tue Jul 27 06:13:57 2004
> +++ libraries/javalib/java/net/Socket.java	Tue Sep 14 16:04:32 2004
> @@ -479,7 +479,8 @@
>  
>    /**
>     * Returns the local address to which this socket is bound.  If this socket
> -   * is not connected, then <code>null</code> is returned.
> +   * is not connected, then <code>InetAddress.anyLocalAddress()</code> is
> +   * returned.
>     *
>     * @return The local address
>     *

Sun's API docs is obviously broken. Copying that brokenness into our own
API docs doesn't make a lot of sense to me. I propose this wording
instead:

If this socket is not connected the isAnyLocalAddress() method of the
returned InetAddress will return true.

/noa


-- 
And the lions ate the christians and the christians burned the witches,
and even I am out of explanations -- Ola Salo
gpg fingerprint: F3C4 AC90 B885 FE15 344B  4D05 220B 7662 A190 6F09





More information about the kaffe mailing list