JDK-6495924 : getSupportedAttributeValues fails when called from multiple threads
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2006-11-21
  • Updated: 2011-02-16
  • Resolved: 2008-11-24
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0-rc"
Java(TM) SE Runtime Environment (build 1.6.0-rc-b104)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0-rc-b104, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux kowhai 2.6.16.28-xen-dom0 #4 SMP Mon Sep 25 18:45:18 BST 2006 x86_64 Intel(R) Core(TM)2 CPU          6600  @ 2.40GHz GenuineIntel GNU/Linux

EXTRA RELEVANT SYSTEM CONFIGURATION :
At least two print services must be installed to reproduce this bug

A DESCRIPTION OF THE PROBLEM :
PrintService.getSupportedAttributeValues throws a NullPointerException when called from multiple threads.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the given code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
  To run without throwing any exceptions, and to print the media count for each print service installed on that machine.
ACTUAL -
A NullPointerException was thrown.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "Thread-2" java.lang.NullPointerException
        at sun.print.IPPPrintService.getSupportedAttributeValues(IPPPrintService
.java:515)
        at GetMediasTest$1.run(GetMediasTest.java:11)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.standard.Media;

public class GetMediasTest {
    public static void main(String[] args) {
        PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
        for(final PrintService service: services) {
            Thread thread = new Thread() {
                public void run() {
                    service.getSupportedAttributeValues(Media.class, null, null);
                }
            };
            thread.start();
        }
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Replace the contents of the run method with:

synchronized (GetMediasTest.class) {
    service.getSupportedAttributeValues(Media.class, null, null);
}

Comments
EVALUATION Verified as fixed after fixing 6653384. Closing as duplicate.
24-11-2008