-
Bug
-
Resolution: Fixed
-
P3
-
None
-
b26
-
Verified
The "java.net.preferIPv4Stack" and "java.net.preferIPv6Addresses" system properties are specified to affect the ordering and filtering of addresses returned by InetAddress::getAllByName. However they seem to have no effect when the HostsFileNameService provider is selected by specifying the "jdk.net.hosts.file" system property.
It is better to make the platform name service and the hosts file name service to behave similarly with respect to the mentioned system properties.
The following test file that is set as hosts file name service (-Djdk.net.hosts.file=testHostsFile.txt):
127.0.0.1 localhost
::1 ip6-localhost ip6-loopback
3.216.223.146 testHost.com
3.213.162.208 testHost.com
2406:da00:ff10:0:0:0:3447:4a6b testHost.com
2406:da00:ff10:0:0:0:3448:ad37 testHost.com
InetAddress.getAllByName("testHost.com") with no system properties set:
[testHost.com/3.216.223.146, testHost.com/3.213.162.208, testHost.com/2406:da00:ff10:0:0:0:3447:4a6b, testHost.com/2406:da00:ff10:0:0:0:3448:ad37]
InetAddress.getAllByName("testHost.com") results with -Djava.net.preferIPv4Stack=true:
[testHost.com/3.216.223.146, testHost.com/3.213.162.208, testHost.com/2406:da00:ff10:0:0:0:3447:4a6b, testHost.com/2406:da00:ff10:0:0:0:3448:ad37]
InetAddress.getAllByName("testHost.com") results with -Djava.net.preferIPv6Addresses=true:
[testHost.com/3.216.223.146, testHost.com/3.213.162.208, testHost.com/2406:da00:ff10:0:0:0:3447:4a6b, testHost.com/2406:da00:ff10:0:0:0:3448:ad37]
It is better to make the platform name service and the hosts file name service to behave similarly with respect to the mentioned system properties.
The following test file that is set as hosts file name service (-Djdk.net.hosts.file=testHostsFile.txt):
127.0.0.1 localhost
::1 ip6-localhost ip6-loopback
3.216.223.146 testHost.com
3.213.162.208 testHost.com
2406:da00:ff10:0:0:0:3447:4a6b testHost.com
2406:da00:ff10:0:0:0:3448:ad37 testHost.com
InetAddress.getAllByName("testHost.com") with no system properties set:
[testHost.com/3.216.223.146, testHost.com/3.213.162.208, testHost.com/2406:da00:ff10:0:0:0:3447:4a6b, testHost.com/2406:da00:ff10:0:0:0:3448:ad37]
InetAddress.getAllByName("testHost.com") results with -Djava.net.preferIPv4Stack=true:
[testHost.com/3.216.223.146, testHost.com/3.213.162.208, testHost.com/2406:da00:ff10:0:0:0:3447:4a6b, testHost.com/2406:da00:ff10:0:0:0:3448:ad37]
InetAddress.getAllByName("testHost.com") results with -Djava.net.preferIPv6Addresses=true:
[testHost.com/3.216.223.146, testHost.com/3.213.162.208, testHost.com/2406:da00:ff10:0:0:0:3447:4a6b, testHost.com/2406:da00:ff10:0:0:0:3448:ad37]