JDK-8000730 : (so) NIO channels with IPv6 on Windows
  • Type: Backport
  • Backport of: JDK-6230761
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 5.0,6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2012-10-10
  • Updated: 2014-03-24
  • Resolved: 2012-10-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6u34Fixed
Description
FULL PRODUCT VERSION :
java version "1.5.0_01"
Java (TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP
Professional
Version 2002
Service Pack 2

A DESCRIPTION OF THE PROBLEM :
Using IPv6 addresses in conjuction with NIO channels raises a "java.net.SocketException: Address family not supported by protocol
family".

Doing the same operation directly on a socket instance (i.e. without getting the socket from a channel) works.



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Simply execute the piece of code below.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The program should run without exception (as it is the case for linux/solaris boxes on which it has been tested too).

Should display:
==> 1
==> 2
==> 3

ACTUAL -
==> 1
==> 2
java.net.SocketException: Address family not supported by protocol
family: bind
        at sun.nio.ch.Net.bind(Native Method)
        at
sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelI��mpl.java:119)
        at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java��:59)
        at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java��:52)
        at external.ipv6.main(ipv6.java:31)

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Stacktrace is displayed by the application already.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.nio.channels.ServerSocketChannel;


class ipv6 {
    static public void main(String[] notUsed) {
        try {
            byte[] addr = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1};

            InetAddress inetAddr = InetAddress.getByAddress(addr);

            InetSocketAddress addr_8501 = new
InetSocketAddress(inetAddr, 8501);
            InetSocketAddress addr_8502 = new
InetSocketAddress(inetAddr, 8502);

            System.out.println("==> 1");

            ServerSocket serverSocket = new ServerSocket();
            serverSocket.bind(addr_8501); // This works

            System.out.println("==> 2");

            ServerSocketChannel channel = ServerSocketChannel.open();
            channel.socket().bind(addr_8502); //This does not work

            System.out.println("==> 3");
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
} 

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Unknown.
###@###.### 2005-2-18 06:41:28 GMT