On Fri, 22 Nov 2024 09:32:43 GMT, Volkan Yazıcı <d...@openjdk.org> wrote:

>> This PR, addressing 8343791, changes `Socket::connect()` methods to close 
>> the `Socket` in the event that the connection cannot be established, the 
>> timeout expires before the connection is established, or the socket address 
>> is unresolved.
>> 
>> `tier3` tests pass against the 9f00f61d3b7fa42a5e23a04f80bb4bb1a2076ef2.
>
> Volkan Yazıcı has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Improve naming in tests

I think we should update the socket adaptor at the same time, can you add the 
following to the change:

diff --git a/src/java.base/share/classes/sun/nio/ch/SocketAdaptor.java 
b/src/java.base/share/classes/sun/nio/ch/SocketAdaptor.java
index cbcfd79378c..191fa177dea 100644
--- a/src/java.base/share/classes/sun/nio/ch/SocketAdaptor.java
+++ b/src/java.base/share/classes/sun/nio/ch/SocketAdaptor.java
@@ -35,6 +35,7 @@
 import java.net.SocketException;
 import java.net.SocketOption;
 import java.net.StandardSocketOptions;
+import java.net.UnknownHostException;
 import java.nio.channels.SocketChannel;
 import java.util.Set;
 
@@ -85,6 +86,14 @@ public void connect(SocketAddress remote) throws IOException 
{
     public void connect(SocketAddress remote, int timeout) throws IOException {
         if (remote == null)
             throw new IllegalArgumentException("connect: The address can't be 
null");
+        if (remote instanceof InetSocketAddress isa && isa.isUnresolved()) {
+            if (!sc.isOpen())
+                throw new SocketException("Socket is closed");
+            if (sc.isConnected())
+                throw new SocketException("Already connected");
+            close();
+            throw new UnknownHostException(remote.toString());
+        }
         if (timeout < 0)
             throw new IllegalArgumentException("connect: timeout can't be 
negative");
         try {

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

PR Comment: https://git.openjdk.org/jdk/pull/22160#issuecomment-2496045458

Reply via email to