-
Bug
-
Resolution: Fixed
-
P3
-
5.0, 5.0u1
-
01
-
generic, x86, sparc
-
generic, linux, solaris_2.6, solaris_9, windows_xp
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2117584 | 6 | Michael McMahon | P3 | Resolved | Fixed | mustang |
JDK-2120922 | 1.4.2_07 | Xuyang Jiang | P3 | Resolved | Fixed | b02 |
The interpretation of this property seems to be broken. Consider the following test case on SuSE 9.1 or Mandrake 10 systems - both distribution ships with IPv6 enabled and /etc/hosts configured as follows :-
127.0.0.1 localhost
# special IPv6 addresses
::1 localhost ipv6-localhost ipv6-loopback
In these environments InetAddress.getAllByName("localhost") correctly resolves to ::1 and 127.0.0.1 but the addresses are returned in the wrong order. The implication is that InetAddress.getByName("localhost") resolves to ::1 even when the preferIPv6Addresses property is explicitly set to false.
The bug appears to be in the sorting implementation - if this test is run with preferIPv6Addresses set to true then the IPv4 address is returned first.
Note that the bug breaks Oracle tools on SuSE 9.1 and is likely to break other applications that attempt to connect to "localhost". The bug is not a regression in 1.5.0 and also duplicates with 1.4.2.
import java.net.*;
public class Test {
public static void main(String args[]) throws UnknownHostException {
InetAddress lh = InetAddress.getByName("localhost");
InetAddress addrs[] = InetAddress.getAllByName("localhost");
boolean hasIPv4Address = false;
boolean hasIPv6Address = false;
for (InetAddress addr: addrs) {
if (addr instanceof Inet4Address) {
hasIPv4Address = true;
}
if (addr instanceof Inet6Address) {
hasIPv6Address = true;
}
if (hasIPv4Address && hasIPv6Address) {
break;
}
}
String prop = System.getProperty("java.net.preferIPv6Addresses");
boolean preferIPv6Addresses = (prop == null) ? false : prop.equals("true");
System.out.println("java.net.preferIPv6Addresses: " + preferIPv6Addresses);
System.out.println("localhost resolves to:");
for (InetAddress addr: addrs) {
System.out.println(" " + addr);
}
System.out.println("InetAddres.getByName returned: " + lh);
boolean failed = false;
if (preferIPv6Addresses && hasIPv6Address) {
if (!(lh instanceof Inet6Address)) failed = true;
}
if (!preferIPv6Addresses && hasIPv4Address) {
if (!(lh instanceof Inet4Address)) failed = true;
}
if (failed) {
throw new RuntimeException("Test failed!");
}
}
}
###@###.### 10/12/04 20:24 GMT
- backported by
-
JDK-2117584 InetAddress.getAllByName does not obey setting of java.net.preferIPv6Addresses
-
- Resolved
-
-
JDK-2120922 InetAddress.getAllByName does not obey setting of java.net.preferIPv6Addresses
-
- Resolved
-
- duplicates
-
JDK-6180108 SocketPermission("127.0.0.1:3000",...) does not imply SocketPermission("localhost:3000",...)
-
- Closed
-
-
JDK-5092451 java/net/InetAddress.getByName() does not always return the expected address typ
-
- Closed
-
-
JDK-5109523 PrintServiceLookup on Linux does not show any printers, while jre1.4.2_05 does
-
- Closed
-
-
JDK-5083013 connecting to IPv4 server on dual stack host fails
-
- Closed
-