7088747: Use multicatch in Socket constructor
authormichaelm
Fri, 09 Sep 2011 15:24:35 +0100
changeset 10439 b36f86ad26e1
parent 10438 9607eb55d49f
child 10440 b90cf2f98868
7088747: Use multicatch in Socket constructor Reviewed-by: alanb
jdk/src/share/classes/java/net/Socket.java
--- a/jdk/src/share/classes/java/net/Socket.java	Fri Sep 09 14:14:01 2011 +0100
+++ b/jdk/src/share/classes/java/net/Socket.java	Fri Sep 09 15:24:35 2011 +0100
@@ -420,15 +420,14 @@
             createImpl(stream);
             if (localAddr != null)
                 bind(localAddr);
-            if (address != null)
-                connect(address);
-        } catch (IOException e) {
-            close();
+            connect(address);
+        } catch (IOException | IllegalArgumentException | SecurityException e) {
+            try {
+                close();
+            } catch (IOException ce) {
+                e.addSuppressed(ce);
+            }
             throw e;
-        } finally {
-            // if bind() or connect threw a runtime exception
-            if ((localAddr != null && !bound) || (address != null && !connected))
-                close();
         }
     }