Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6921585

PrintServiceLookup.lookupPrintServices is not dynamic on Windows

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P3 P3
    • 9
    • 6u10
    • client-libs
    • 2d
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      build 1.6.0_12-b04

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP, 32 bit

      A DESCRIPTION OF THE PROBLEM :
      While my Java application is running, if the user adds a new printer via Windows print settings, PrintServiceLookup.lookupPrintServices does not return that printer. This is even worse if the user makes the new printer the default-- our code tries to initially select the default printer.

      This appears to be the same issue as 4744405, but supposedly that was not an issue on Windows (and has been fixed on other platforms).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Run the sample code below
      2) Click on the button to bring up the print dialog. Press Cancel to close it.
      3) While the process is still active, add a new printer via Windows print setup and make it the default printer.
      4) Click on the button again to reopen the print dialog.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The print dialog should open with the newly added printer as the selected printer.
      ACTUAL -
      Exception prints. PrintServiceLookup.lookupDefaultPrintService() returns the new printer, but it is not present in the list of all available printers.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.IllegalArgumentException: services must contain defaultService
      at javax.print.ServiceUI.printDialog(ServiceUI.java:164)
      at PrintTest$1.actionPerformed(PrintTest.java:22)
      at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
      at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
      at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
      at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
      at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
      at java.awt.Component.processMouseEvent(Component.java:6216)
      at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
      at java.awt.Component.processEvent(Component.java:5981)
      at java.awt.Container.processEvent(Container.java:2041)
      at java.awt.Component.dispatchEventImpl(Component.java:4583)
      at java.awt.Container.dispatchEventImpl(Container.java:2099)
      at java.awt.Component.dispatchEvent(Component.java:4413)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4556)
      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4220)
      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4150)
      at java.awt.Container.dispatchEventImpl(Container.java:2085)
      at java.awt.Window.dispatchEventImpl(Window.java:2475)
      at java.awt.Component.dispatchEvent(Component.java:4413)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.print.DocFlavor;
      import javax.print.PrintService;
      import javax.print.PrintServiceLookup;
      import javax.print.ServiceUI;
      import javax.print.attribute.HashPrintRequestAttributeSet;
      import javax.print.attribute.PrintRequestAttributeSet;
      import javax.swing.AbstractAction;
      import javax.swing.JButton;
      import javax.swing.JFrame;
      import java.awt.event.ActionEvent;

      public class PrintTest {
          public static void main(String[] args) {
              final JFrame frame = new JFrame();
              final AbstractAction printAction = new AbstractAction("Show print dialog") {
                  public void actionPerformed(ActionEvent e) {
                      PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
                      DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
                      PrintService[] printService = PrintServiceLookup.lookupPrintServices(flavor, pras);

                      try {
                          ServiceUI.printDialog(null, frame.getLocationOnScreen().x + 100, frame.getLocationOnScreen().y + 100,
                                  printService, PrintServiceLookup.lookupDefaultPrintService(),
                                  flavor, pras);
                      }
                      catch (IllegalArgumentException ex) {
                          ex.printStackTrace();
                      }
                  }
              };

              frame.add(new JButton(printAction));
              frame.pack();
              frame.setVisible(true);
          }
      }

      ---------- END SOURCE ----------
      Not reproducible in 6u10, 6u13, and above. Asked submitter for more info regarding printer trying to add and number of printers installed. Will re-open if I get any new info and can reproduce the same problem.

            psadhukhan Prasanta Sadhukhan
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: