Hi,

I think we need the patch below to fix the following case:

Socket sock = new Socket();
sock.setKeepAlive(false);

Currently this throws a NullPointerException (on IKVM at least), because the 
impl.create() hasn't been called yet.

Any comments?

Regards,
Jeroen


Index: java/net/Socket.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/Socket.java,v
retrieving revision 1.61
diff -u -r1.61 Socket.java
--- java/net/Socket.java        12 Feb 2007 18:56:48 -0000      1.61
+++ java/net/Socket.java        5 Mar 2007 14:12:35 -0000
@@ -83,6 +83,11 @@
   SocketImpl impl;

   /**
+   * True if impl.create() has been called.
+   */
+  private boolean implCreated;
+
+  /**
    * True if the socket is bound.
    * Package private so it can be set from ServerSocket when accept is called.
    */
@@ -326,6 +331,18 @@

   private SocketImpl getImpl() throws SocketException
   {
+    if (! implCreated)
+      {
+        try
+          {
+            impl.create(true);
+          }
+        catch (IOException x)
+          {
+            throw (SocketException) new SocketException().initCause(x);
+          }
+        implCreated = true;
+      }
     return impl;
   }

@@ -359,7 +376,6 @@
     // bind to address/port
     try
       {
-       getImpl().create(true);
        getImpl().bind(tmp.getAddress(), tmp.getPort());
        bound = true;
       }

Reply via email to