The JCK revealed a race condition in UnixPrintServiceLookup when either
sun.java2d.print.polling=false or getDefaultPrintService() returns
before the polling PrintServices thread has started.  This causes
multiple copies of IPPPrintService to be instantiated.  The test below
fails on all platforms with -Dsun.java2d.print.polling=false and on
some platforms with -Dsun.java2d.print.polling=true, depending on how
long it takes the polling loop to start.

The simple fix is to ensure that we call refreshServices() from the
constructor, ensuring that everything is initialized before the first
call to lookupDefaultPrintService().

Is this patch a good approach to fixing the problem?

Andrew.


----------------------------------------------------------------------------------
import javax.print.PrintService;
import javax.print.PrintServiceLookup;


public class Test {

    public static void main(String argv[]) {
        trial();
    }

    static void trial() {
        PrintService pserv1 = PrintServiceLookup.lookupDefaultPrintService();
        PrintService[] pservs = PrintServiceLookup.lookupPrintServices(null, 
null);
        PrintService pserv2 = PrintServiceLookup.lookupDefaultPrintService();
        
        if (pserv1.hashCode() != pserv2.hashCode()) {
            System.err.println("Different hashCodes for equal print "
                            + "services: " + pserv1.hashCode() + " "
                            + pserv2.hashCode());
        }
    }
}

----------------------------------------------------------------------------------

--- 
/notnfs/user/TCK_candidate/icedtea6-1.2/openjdk/jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java
       2008-04-11 04:18:13.000000000 -0400
+++ sun/print/UnixPrintServiceLookup.java       2008-07-30 12:45:40.000000000 
-0400
@@ -163,6 +163,12 @@


     public UnixPrintServiceLookup() {
+       try {
+           refreshServices();
+       } catch (Exception se) {
+           IPPPrintService.debug_println(debugPrefix+"Exception in 
refreshServices()");
+       }
+
         // start the printer listener thread
         if (pollServices) {
             PrinterChangeListener thr = new PrinterChangeListener();

Reply via email to