src/share/classes/sun/rmi/transport/proxy/RMIMasterSocketFactory.java

Print this page

        

@@ -72,32 +72,33 @@
     private static final boolean eagerHttpFallback =
         java.security.AccessController.doPrivileged(new GetBooleanAction(
             "sun.rmi.transport.proxy.eagerHttpFallback")).booleanValue();
 
     /** table of hosts successfully connected to and the factory used */
-    private Hashtable successTable = new Hashtable();
+    private Hashtable<String, RMISocketFactory> successTable = 
+        new Hashtable<>();
 
     /** maximum number of hosts to remember successful connection to */
     private static final int MaxRememberedHosts = 64;
 
     /** list of the hosts in successTable in initial connection order */
-    private Vector hostList = new Vector(MaxRememberedHosts);
+    private Vector<String> hostList = new Vector<>(MaxRememberedHosts);
 
-    /** default factory to initally use for direct socket connection */
+    /** default factory for initial use for direct socket connection */
     protected RMISocketFactory initialFactory = new RMIDirectSocketFactory();
 
     /** ordered list of factories to try as alternate connection
       * mechanisms if a direct socket connections fails */
-    protected Vector altFactoryList;
+    protected Vector<RMISocketFactory> altFactoryList;
 
     /**
      * Create a RMIMasterSocketFactory object.  Establish order of
      * connection mechanisms to attempt on createSocket, if a direct
      * socket connection fails.
      */
     public RMIMasterSocketFactory() {
-        altFactoryList = new Vector(2);
+        altFactoryList = new Vector<RMISocketFactory>(2);
         boolean setFactories = false;
 
         try {
             String proxyHost;
             proxyHost = java.security.AccessController.doPrivileged(

@@ -150,11 +151,11 @@
 
         /*
          * If we remember successfully connecting to this host before,
          * use the same factory.
          */
-        factory = (RMISocketFactory) successTable.get(host);
+        factory = successTable.get(host);
         if (factory != null) {
             if (proxyLog.isLoggable(Log.BRIEF)) {
                 proxyLog.log(Log.BRIEF,
                     "previously successful factory found: " + factory);
             }

@@ -205,14 +206,12 @@
 
             proxyLog.log(Log.BRIEF, "direct socket connection successful");
 
             return initialSocket;
 
-        } catch (UnknownHostException e) {
+        } catch (UnknownHostException | NoRouteToHostException e) {
             initialFailure = e;
-        } catch (NoRouteToHostException e) {
-            initialFailure = e;
         } catch (SocketException e) {
             if (eagerHttpFallback) {
                 initialFailure = e;
             } else {
                 throw e;

@@ -225,26 +224,26 @@
                         "direct socket connection failed: ", initialFailure);
                 }
 
                 // Finally, try any alternate connection mechanisms.
                 for (int i = 0; i < altFactoryList.size(); ++ i) {
-                    factory = (RMISocketFactory) altFactoryList.elementAt(i);
+                    factory = altFactoryList.elementAt(i);
                     try {
                         if (proxyLog.isLoggable(Log.BRIEF)) {
                             proxyLog.log(Log.BRIEF,
                                 "trying with factory: " + factory);
                         }
-
                         // For HTTP connections, the output (POST request) must
                         // be sent before we verify a successful connection.
                         // So, sacrifice a socket for the sake of testing...
                         // The following sequence should verify a successful
                         // HTTP connection if no IOException is thrown.
-                        Socket testSocket = factory.createSocket(host, port);
+                        try (Socket testSocket = 
+                                factory.createSocket(host, port)) {
                         InputStream in = testSocket.getInputStream();
                         int b = in.read(); // probably -1 for EOF...
-                        testSocket.close();
+                        }
                     } catch (IOException ex) {
                         if (proxyLog.isLoggable(Log.BRIEF)) {
                             proxyLog.log(Log.BRIEF, "factory failed: ", ex);
                         }
 

@@ -274,14 +273,12 @@
                         fallbackSocket.close();
                     return initialSocket;
                 }
                 // if connector ever does get socket, it won't be used
                 connector.notUsed();
-            } catch (UnknownHostException e) {
+            } catch (UnknownHostException | NoRouteToHostException e) {
                 initialFailure = e;
-            } catch (NoRouteToHostException e) {
-                initialFailure = e;
             } catch (SocketException e) {
                 if (eagerHttpFallback) {
                     initialFailure = e;
                 } else {
                     throw e;