On Wed, 20 Nov 2024 12:42:46 GMT, Volkan Yazıcı <d...@openjdk.org> wrote:
>> 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. Imagine `bind()` succeeding, yet `connect()` failing due to an `IAE` thrown by `SocketImpl#connect()`. This would leave the socket in `BOUND` state. Hence, shouldn't we include the `connect()` in the try-catch block too? ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/22160#discussion_r1850325806