On Wed, 20 Nov 2024 08:37:20 GMT, Alan Bateman <al...@openjdk.org> wrote:
>> src/java.base/share/classes/java/net/Socket.java line 503: >> >>> 501: // `connect()` already closes the socket on failures, yet >>> `bind()` doesn't, and hence: >>> 502: closeQuietly(throwable); >>> 503: throw throwable; >> >> Would you mind adding `assert address instanceof InetSocketAddress isa && >> !isa.isUnresolved();` to the start of this (private) constructor as that >> will ensure we have the right pre-conditions and avoid further discussion >> about other socket address types. > > If you take on board the other feedback then you can reduce the scope of the > try-catch to just the bind, e.g. > > if (localAddr != null) { > try { > bind(localAddr); > } catch (Throwable ex) { > try { > close(); > } catch (Throwable ce) { ex.addSuppressed(ce); } > throw ex; > } > } > connect(address); // closes Socket if it throws Fixed in 424fc8ccd3a495a49f859f0cfc563cf463b3efeb. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/22160#discussion_r1850252593