changeset 4562:e995c36bb1eb

7088747: Use multicatch in Socket constructor Reviewed-by: alanb
author michaelm
date Fri, 09 Sep 2011 15:24:35 +0100
parents 0ba4b29c7d9a
children c91176b44c9b
files src/share/classes/java/net/Socket.java
diffstat 1 files changed, 7 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/net/Socket.java	Fri Sep 09 14:14:01 2011 +0100
+++ b/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();
         }
     }