--- /home/cpdev/src/classpath/java/net/ServerSocket.java	2005-07-02 21:03:35.000000000 +0000
+++ java/net/ServerSocket.java	2005-06-30 05:34:40.000000000 +0000
@@ -76,9 +76,9 @@
   private SocketImpl impl;
 
   /**
-   * We need to retain the local address even after the socket is closed.
+   * True if socket is bound.
    */
-  private InetSocketAddress local;
+  private boolean bound;
 
   /*
    * This constructor is only used by java.nio.
@@ -238,9 +238,7 @@
       {
 	impl.bind(addr, tmp.getPort());
 	impl.listen(backlog);
-	local = new InetSocketAddress(
-            (InetAddress) impl.getOption(SocketOptions.SO_BINDADDR),
-            impl.getLocalPort());
+	bound = true;
       }
     catch (IOException exception)
       {
@@ -266,10 +264,18 @@
    */
   public InetAddress getInetAddress()
   {
-    if (local == null)
+    if (! isBound())
       return null;
 
-    return local.getAddress();
+    try
+      {
+	return (InetAddress) impl.getOption(SocketOptions.SO_BINDADDR);
+      }
+    catch (SocketException e)
+      {
+	// This never happens as we are bound.
+	return null;
+      }
   }
 
   /**
@@ -279,10 +285,10 @@
    */
   public int getLocalPort()
   {
-    if (local == null)
+    if (! isBound())
       return -1;
 
-    return local.getPort();
+    return impl.getLocalPort();
   }
 
   /**
@@ -294,7 +300,10 @@
    */
   public SocketAddress getLocalSocketAddress()
   {
-    return local;
+    if (! isBound())
+      return null;
+
+    return new InetSocketAddress(getInetAddress(), getLocalPort());
   }
 
   /**
@@ -383,6 +392,7 @@
 
     impl.close();
     impl = null;
+    bound = false;
 
     if (getChannel() != null)
       getChannel().close();
@@ -413,7 +423,7 @@
    */
   public boolean isBound()
   {
-    return local != null;
+    return bound;
   }
 
   /**
