8346017: Socket.connect specified to throw UHE for unresolved address is problematic for SOCKS V5 proxy

Reviewed-by: dfuchs, alanb
This commit is contained in:
Volkan Yazıcı 2024-12-18 09:43:06 +00:00 committed by Daniel Fuchs
parent 5b703c7023
commit 9e8aa855fe
3 changed files with 234 additions and 19 deletions

View file

@ -569,9 +569,8 @@ public class Socket implements java.io.Closeable {
/**
* Connects this socket to the server.
*
* <p> If the endpoint is an unresolved {@link InetSocketAddress}, or the
* connection cannot be established, then the socket is closed, and an
* {@link IOException} is thrown.
* <p> If the connection cannot be established, then the socket is closed,
* and an {@link IOException} is thrown.
*
* <p> This method is {@linkplain Thread#interrupt() interruptible} in the
* following circumstances:
@ -591,8 +590,8 @@ public class Socket implements java.io.Closeable {
* @param endpoint the {@code SocketAddress}
* @throws IOException if an error occurs during the connection, the socket
* is already connected or the socket is closed
* @throws UnknownHostException if the endpoint is an unresolved
* {@link InetSocketAddress}
* @throws UnknownHostException if the connection could not be established
* because the endpoint is an unresolved {@link InetSocketAddress}
* @throws java.nio.channels.IllegalBlockingModeException
* if this socket has an associated channel,
* and the channel is in non-blocking mode
@ -609,9 +608,8 @@ public class Socket implements java.io.Closeable {
* A timeout of zero is interpreted as an infinite timeout. The connection
* will then block until established or an error occurs.
*
* <p> If the endpoint is an unresolved {@link InetSocketAddress}, the
* connection cannot be established, or the timeout expires before the
* connection is established, then the socket is closed, and an
* <p> If the connection cannot be established, or the timeout expires
* before the connection is established, then the socket is closed, and an
* {@link IOException} is thrown.
*
* <p> This method is {@linkplain Thread#interrupt() interruptible} in the
@ -634,8 +632,8 @@ public class Socket implements java.io.Closeable {
* @throws IOException if an error occurs during the connection, the socket
* is already connected or the socket is closed
* @throws SocketTimeoutException if timeout expires before connecting
* @throws UnknownHostException if the endpoint is an unresolved
* {@link InetSocketAddress}
* @throws UnknownHostException if the connection could not be established
* because the endpoint is an unresolved {@link InetSocketAddress}
* @throws java.nio.channels.IllegalBlockingModeException
* if this socket has an associated channel,
* and the channel is in non-blocking mode
@ -660,12 +658,6 @@ public class Socket implements java.io.Closeable {
if (!(endpoint instanceof InetSocketAddress epoint))
throw new IllegalArgumentException("Unsupported address type");
if (epoint.isUnresolved()) {
var uhe = new UnknownHostException(epoint.getHostName());
closeSuppressingExceptions(uhe);
throw uhe;
}
InetAddress addr = epoint.getAddress();
checkAddress(addr, "connect");