--- 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();
}
}