Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 5087907
Votes 0
Synopsis InetAddress.getAllByName does not obey setting of java.net.preferIPv6Addresses
Category java:classes_net
Reported Against tiger , 1.5.0_01 , tiger-rc
Release Fixed 1.5.0_01, mustang(Bug ID:2117584) , 1.4.2_07(b02) (Bug ID:2120922)
State 10-Fix Delivered, bug
Priority: 3-Medium
Related Bugs 6180108 , 5083013 , 5092451 , 5104474 , 5109523
Submit Date 17-AUG-2004
Description
InetAddress.getAllByName is supposed to examine the java.net.preferIPv6Addresses system property and sort the results according. The default value for the property is false so on a dual stack system this should mean that the results are ordered so that the IPv4 addresses are first in the list. 

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!");
        }
    }
 
}
  xxxxx@xxxxx   10/12/04 20:24 GMT
Work Around
Disable IPv6 (/etc/modules.conf or /etc/modprobe.conf depending on if 2.4 or 2.6 kernel). Alternatively run application with java.net.preferIPv4Stack system property set to true.
  xxxxx@xxxxx   2004-08-17
  xxxxx@xxxxx   10/27/04 23:16 GMT
Evaluation
will fix asap.

  xxxxx@xxxxx   2004-08-17

====================================

This is also the cause of 5109523:
PrintServiceLookup on Linux does not show any printers.
In JDK 1.5 the direct CUPS support fails because connecting to the
local cups server fails.
  xxxxx@xxxxx   10/27/04 23:16 GMT
Comments
  
  Include a link with my name & email   

Submitted On 10-NOV-2005
rlwsoftware
I would caution that there are other reasons that CUPS will not report any printers. If cupsd.conf is set to require authentication (e.g. AuthType BasicDigest instead of AuthType None) for <Location /> (i.e. the root CUPS location), then the default PrintServiceLookup class will not be able to pass a username/password and no printers will be returned.  Solution is to set AuthType None or use Jipsi to get an IPP-specific Print Service Lookup.

// create an instance of the IPPPrintServiceLookup
	PrintServiceLookup lookup = 
		new IppPrintServiceLookup(
		    new java.net.URI("ipp://127.0.0.1:631"),
		    "username",
		    "password");
	
	// get all services from lookup
	PrintService[] services = lookup.getPrintServices();

http://www.lohndirekt.de/software/jipsi_quickstart_drucksoftware.html



PLEASE NOTE: JDK6 is formerly known as Project Mustang