non-blocking SocketChannel connect broken on Windows 8
Jeroen Frijters
jeroen at sumatra.nl
Thu Sep 29 07:04:18 PDT 2011
Hi,
While testing on Windows 8 I found a bug in SocketChannelImpl.connect() when configured non-blocking.
Here's repro:
import java.net.*;
import java.nio.channels.*;
public class test
{
public static void main(String[] args) throws Exception
{
SocketChannel sc = SocketChannel.open();
sc.configureBlocking(false);
sc.connect(new InetSocketAddress("google.com", 12345));
}
}
When run on the Windows 8 Developer Preview this throws the following exception:
Exception in thread "main" java.net.SocketException: Invalid argument: getsockname
at sun.nio.ch.Net.localInetAddress(Native Method)
at sun.nio.ch.Net.localAddress(Net.java:389)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:639)
at test.main(test.java:10)
When you look at the code the problem is obvious. The connect method tries to get the localAddress while the connection is still pending, it should only do this after the connection attempt has finished.
Regards,
Jeroen
More information about the net-dev
mailing list