RFR: 8343791: Socket.connect API should document whether the socket will be closed when hostname resolution fails or another error occurs [v3]

Daniel Fuchs dfuchs at openjdk.org
Tue Nov 19 17:24:43 UTC 2024


On Tue, 19 Nov 2024 10:06:02 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> Volkan Yazıcı has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Apply review suggestions by Alan & Daniel
>
> src/java.base/share/classes/java/net/Socket.java line 706:
> 
>> 704:         try {
>> 705:             getImpl().connect(epoint, timeout);
>> 706:         } catch (IOException error) {
> 
> At L680 we reject an endpoint that is not an InetSocketAddresss. I think we should follow this with a check to ensure that the address is resolved, that way Socket does all the validation before delegation to the SocketImpl. It means if getImpl().connect(..) throws any exception or error then you can close the Socket, meaning you can catch Throwable.

The spec is still not right: we throw SocketException if the socket is already connected, but we do not close the socket in that case.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/22160#discussion_r1848762389


More information about the net-dev mailing list