David Daney wrote:
> Jeroen Frijters wrote:
> >              throw new RuntimeException("error instantiating default
> > socket factory: "
> > -                                       + ex.toString());
> >   
> That sounds more like an InternalError than the super-generic 
> RuntimeException.

Possibly. I don't know enough about this stuff to tell. I have, however,
since discovered that the current code is wrong. When the factory is not
properly configured it is supposed to return a factory that throws
exceptions upon invocation of the factory methods, not at this stage.

I've got a patch (attached), but I'm going on vacation tomorrow and
don't have time to properly test it and check it in, but if someone
would like to do so, that would be great.

Regards,
Jeroen
Index: javax/net/ssl/SSLServerSocketFactory.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/javax/net/ssl/SSLServerSocketFactory.java,v
retrieving revision 1.3
diff -u -r1.3 SSLServerSocketFactory.java
--- javax/net/ssl/SSLServerSocketFactory.java   2 Jul 2005 20:32:45 -0000       
1.3
+++ javax/net/ssl/SSLServerSocketFactory.java   11 Dec 2006 15:16:13 -0000
@@ -38,6 +38,9 @@
 
 package javax.net.ssl;
 
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.ServerSocket;
 import java.security.KeyStore;
 import java.security.Security;
 
@@ -138,8 +141,9 @@
           }
         catch (Exception ex)
           {
-            throw new RuntimeException("error instantiating default server 
socket factory: "
-                                       + ex.toString());
+            return new ErrorServerSocketFactory(new RuntimeException(
+                "error instantiating default server socket factory: "
+                                       + ex.toString(), ex));
           }
       }
     try
@@ -149,7 +153,52 @@
     catch (Exception e)
       {
       }
-    throw new RuntimeException("no SSLSocketFactory implementation available");
+    return new ErrorServerSocketFactory(new RuntimeException(
+        "no SSLSocketFactory implementation available"));
+  }
+
+  private static final class ErrorServerSocketFactory
+    extends SSLServerSocketFactory
+  {
+    private RuntimeException x;
+
+    ErrorServerSocketFactory(RuntimeException x)
+    {
+      this.x = x;
+    }
+
+    public ServerSocket createServerSocket() throws IOException
+    {
+      throw (IOException) new IOException().initCause(x);
+    }
+
+    public ServerSocket createServerSocket(int port) throws IOException
+    {
+      throw (IOException) new IOException().initCause(x);
+    }
+
+    public ServerSocket createServerSocket(int port, int backlog)
+      throws IOException
+    {
+      throw (IOException) new IOException().initCause(x);
+    }
+
+    public ServerSocket createServerSocket(int port, int backlog,
+                                           InetAddress ifAddress)
+      throws IOException
+    {
+      throw (IOException) new IOException().initCause(x);
+    }
+
+    public String[] getDefaultCipherSuites()
+    {
+      throw new RuntimeException(x);
+    }
+
+    public String[] getSupportedCipherSuites()
+    {
+      throw new RuntimeException(x);
+    }
   }
 
   // Abstract methods.
Index: javax/net/ssl/SSLSocketFactory.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/net/ssl/SSLSocketFactory.java,v
retrieving revision 1.5
diff -u -r1.5 SSLSocketFactory.java
--- javax/net/ssl/SSLSocketFactory.java 11 Dec 2006 13:45:55 -0000      1.5
+++ javax/net/ssl/SSLSocketFactory.java 11 Dec 2006 15:15:27 -0000
@@ -39,6 +39,7 @@
 package javax.net.ssl;
 
 import java.io.IOException;
+import java.net.InetAddress;
 import java.net.Socket;
 import java.security.KeyStore;
 import java.security.Security;
@@ -141,8 +142,9 @@
           }
         catch (Exception ex)
           {
-            throw new RuntimeException("error instantiating default socket 
factory: "
-                                       + ex.toString(), ex);
+            return new ErrorSocketFactory(new RuntimeException(
+                "error instantiating default socket factory: " + ex.toString(),
+                ex));
           }
       }
     try
@@ -152,7 +154,65 @@
     catch (Exception e)
       {
       }
-    throw new RuntimeException("no SSLSocketFactory implementation available");
+    return new ErrorSocketFactory(new RuntimeException(
+        "no SSLSocketFactory implementation available"));
+  }
+
+  private static final class ErrorSocketFactory extends SSLSocketFactory
+  {
+    private RuntimeException x;
+
+    ErrorSocketFactory(RuntimeException x)
+    {
+      this.x = x;
+    }
+
+    public Socket createSocket() throws IOException
+    {
+      throw (IOException) new IOException().initCause(x);
+    }
+
+    public Socket createSocket(String host, int port)
+      throws IOException
+    {
+      throw (IOException) new IOException().initCause(x);
+    }
+
+    public Socket createSocket(String host, int port, InetAddress localHost,
+                               int localPort)
+      throws IOException
+    {
+      throw (IOException) new IOException().initCause(x);
+    }
+
+    public Socket createSocket(InetAddress host, int port) throws IOException
+    {
+      throw (IOException) new IOException().initCause(x);
+    }
+
+    public Socket createSocket(InetAddress hast, int port, InetAddress 
localHost,
+                               int localPort)
+      throws IOException
+    {
+      throw (IOException) new IOException().initCause(x);
+    }
+
+    public String[] getDefaultCipherSuites()
+    {
+      throw new RuntimeException(x);
+    }
+
+    public String[] getSupportedCipherSuites()
+    {
+      throw new RuntimeException(x);
+    }
+
+    public Socket createSocket(Socket s, String host, int port,
+                               boolean autoClose)
+      throws IOException
+    {
+      throw new RuntimeException(x);
+    }
   }
 
   // Abstract methods.

Reply via email to