JDK-8016521 : InetAddress should not always re-order addresses returned from name service
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 6,7,8,9
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2013-06-13
  • Updated: 2023-08-05
  • Resolved: 2016-05-24
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 9
9 b121Fixed
Related Reports
Relates :  
Relates :  
Description
RFC 3484 defines the default address selection for IPv6. It is basically defining a number of rules for ordering the result from getaddrinfo() to observe standard behaviour (prefer ipv6 if supported, allow administrative redefinition). Linux and Windows have elaborate mechanisms to influence getaddrinfo (net sh int ipv6 prefixpolicy on Windows and /etc/gai.conf on Linux).

Unfortunatelly Java is re-ordering that answer (in Java_java_net_Inet6AddressImpl_lookupAllHostAddr based on preverIPv6). It would be good if instead of preferIPV6=true/false there would be a preferIPV6=true/false/donottouch, with donottouch beening the RFC 3484 compliant default.

I am talking about

http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/272483f6650b/src/solaris/native/java/net/Inet6AddressImpl.c Line 140ff

According to RFC 3493 you should instead use the AI_ADDRCONFIG to automatically be sensitive to hosts stack configuration. 

see discussion on net-dev mailing list
  http://mail.openjdk.java.net/pipermail/net-dev/2013-June/006543.html
Comments
URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/3a4e4503049b User: lana Date: 2016-06-01 18:59:16 +0000
01-06-2016

URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/3a4e4503049b User: chegar Date: 2016-05-24 20:38:35 +0000
24-05-2016

I don't think this is critical for jdk8 so I've changed the fixVersion to tbd_major. It can be changed later once there is a definitely plan for this one.
13-09-2013

Initial thoughts here are to keep the default behavior unchanged, and provide the ability, through the existing java.net.preferIPv6Addresses system property, to preserve the order of addresses returned from the system call. From the Networking IPv6 User Guide, http://docs.oracle.com/javase/1.5.0/docs/guide/net/ipv6_guide/ ---- "IPv6-Related System Properties On dual stack machines, system properties are provided for setting the preferred protocol stack—IPv4 or IPv6—as well as the preferred address family types—inet4 or inet6. IPv6 stack is preferred by default, since on a dual-stack machine IPv6 socket can talk to both IPv4 and IPv6 peers. This setting can be changed through the java.net.preferIPv4Stack=<true|false> system property. By default, we would prefer IPv4 addresses over IPv6 addresses, i.e., when querying the name service (e.g., DNS service), we would return Ipv4 addresses ahead of IPv6 addresses. There are two reasons for this choice: There are some applications that expect an IPv4 address textual format, i.e. "%d.%d.%d.%d". Using an IPv4 address minimizes the surprises; Using IPv4 address, we can use one call (with an IPv6 socket) to reach either a legacy IPv4-only service, or an IPv6 service (unless the IPv6 service is on a Ipv6 only node). This setting can be changed through the system property java.net.preferIPv6Addresses=<true|false>" ---- java.net.preferIPv6Addresses could be updated to accept 'system', to preserve the order of addresses returned from the system. For example: ....the system property java.net.preferIPv6Addresses=<true|false|system>
14-06-2013