jdk/src/share/classes/java/net/Socket.java
changeset 10439 b36f86ad26e1
parent 10437 dfca69ed7f87
child 10596 39b3a979e600
--- 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();
         }
     }