What can go wrong if I simply replace
socket = new Socket()
with
socket = SocketChannel.open().socket()?
Back
There are several.
Why do you want to interrupt the connect() call? Surely all you want is a connect timeout?
Differences in the type of thrown exceptions could break existing code.
For instance, closing a Socket from a different thread while Socket.getInputStream().read() is blocking will result in AsynchronousCloseException after replacing, instead of SocketException that legacy code could be expecting. (AsynchronousCloseException is not a subclass of SocketException.)
However, Socket.getInputStream().read() will still throw SocketException if the close from the other thread gets in before read().