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

Stack Overflow from Printing with Native Dialog while Print Service is disabled

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 9
    • 8, 8u45, 9
    • client-libs
    • 2d
    • x86
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.8.0_45"
      Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
      Java HotSpot(TM) Client VM (build 25.45-b02, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Windows 7 Professional, Service Pack 1

      A DESCRIPTION OF THE PROBLEM :
      We are seeing some of our customers getting a Stack Overflow error on printing. The Stack Trace is at the bottom. This occurs if the Print Spooler on Windows has been stopped or crashed.

      We are trying to bring up the Native dialog for printing with the following code:

              final PrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet();
              PrinterJob printerJob = PrinterJob.getPrinterJob();
              final PageFormat pageFormat = new PageFormat();
              Paper paper = new Paper();
              pageFormat.setPaper(paper);
              attributeSet.add(javax.print.attribute.standard.DialogTypeSelection.NATIVE);
              attributeSet.add(javax.print.attribute.standard.SheetCollate.COLLATED);
              if (printable instanceof LandscapePrintable &&
                  ((LandscapePrintable)printable).isLandscapePrintRequested() ) {
                  attributeSet.add(OrientationRequested.LANDSCAPE);
             }

              if (printerJob.printDialog(attributeSet)) {
                    ...
              }

      Infinite stack starts in printerJob.printDialog(attributeSet), which is a RasterPrinterJob.

      The problem seems to be related to printerJob.getPrintService() returning null and that is causing WPrinterJob.printDialog() to call RasterPrinterJob.printDialog(attributeSet) with the same attributes, which the NATIVE dialog attribute causes RasterPrinterJob.printDialog(attributeSet) to call WPrinterJob.printDialog().

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      I was able to reproduce the error on my local Windows 7 system with the following steps:

      1) Control Panel => Adminstrative Services => Services => Print Spooler => Stop
      2) Attempt to print from Java using the Native Dialog

      Works as expected if the Print Spooler is running, but a missing Print Spooler should not generate a Stack Overflow from Java.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Should not get stuck in a Stack Overflow, but return some error condition or throw some exception.
      ACTUAL -
      Stack Overflow.

      07/10 00:35:38: java.lang.StackOverflowError
      07/10 00:35:38: at sun.awt.windows.WPrinterJob.setNativePrintService(Native Method)
      07/10 00:35:38: at sun.awt.windows.WPrinterJob.setNativePrintServiceIfNeeded(Unknown Source)
      07/10 00:35:38: at sun.awt.windows.WPrinterJob.getPrintService(Unknown Source)
      07/10 00:35:38: at sun.print.RasterPrinterJob.setAttributes(Unknown Source)
      07/10 00:35:38: at sun.awt.windows.WPrinterJob.setAttributes(Unknown Source)
      07/10 00:35:38: at sun.print.RasterPrinterJob.printDialog(Unknown Source)
      07/10 00:35:38: at sun.awt.windows.WPrinterJob.printDialog(Unknown Source)
      ....

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
              final PrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet();
              PrinterJob printerJob = PrinterJob.getPrinterJob();
              final PageFormat pageFormat = new PageFormat();
              Paper paper = new Paper();
              pageFormat.setPaper(paper);
              attributeSet.add(javax.print.attribute.standard.DialogTypeSelection.NATIVE);
              attributeSet.add(javax.print.attribute.standard.SheetCollate.COLLATED);
              if (printable instanceof LandscapePrintable &&
                  ((LandscapePrintable)printable).isLandscapePrintRequested() ) {
                  attributeSet.add(OrientationRequested.LANDSCAPE);
             }

              if (printerJob.printDialog(attributeSet)) {
                    ...
              }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Before calling printerJob.printDialog(attributeSet) test to see if printerJob.getPrintService() returns null.

            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: