Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8004232

(dc) DatagramChannel.bind(null) throws UnsupportedAddressTypeException if IPv4 socket and java.net.preferIPv6Addresses set to true

    XMLWordPrintable

Details

    Description

      This issue causes (at least) 2 JCK test failures:

      api/java_nio/channels/DatagramChannel/DatagramChannel.html#NetworkChannel[bindToAutoAddress_test]
      api/java_nio/channels/DatagramChannel/DatagramChannel.html#NetworkChannel[bindRepeatedly_test]

      The rest is copied from exclude request JCK-7300127:

      --- start of quote ----

       In JavaSE7 (jdk/src/share/classes/sun/nio/ch/DatagramChannelImpl.java)
           public DatagramChannel bind(SocketAddress local) throws IOException {
                 .....
                          InetSocketAddress isa;
                          if (local == null) {
                              isa = new InetSocketAddress(0); <= this will create IPv6 socket
                          } else {
                              isa = Net.checkAddress(local);

                              // only Inet4Address allowed with IPv4 socket
                              if (family == StandardProtocolFamily.INET) {
                                  InetAddress addr = isa.getAddress();
                                  if (!(addr instanceof Inet4Address))
                                      throw new UnsupportedAddressTypeException();
                              }
                          }
                          SecurityManager sm = System.getSecurityManager();
                          if (sm != null) {
                              sm.checkListen(isa.getPort());
                          }
                          Net.bind(family, fd, isa.getAddress(), isa.getPort()); <= family is INET(IPv4)
                          localAddress = Net.localAddress(fd);
                      }
                  }

      So they execute in IPv4 mode (family=INET) *AND* java.net.preferIPv6Addresses is TRUE,
      then InetSoketAddress(0) constructor creates IPv6 address.
      Later it tries to bind with IPv6 address on IPv4 mode.

      ---- end of quote ----

      Attachments

        Issue Links

          Activity

            People

              robm Robert Mckenna
              asutchil Arkadiy Sutchilin (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: