JDK-8133737 : Stack Overflow from Printing with Native Dialog while Print Service is disabled
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 8,8u45,9
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86
  • Submitted: 2015-07-10
  • Updated: 2016-03-24
  • Resolved: 2016-03-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9Resolved
Related Reports
Duplicate :  
Description
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.


Comments
The bug was reproduced by means of the created minimal test case and steps to follow to reproduce the problem from the description of the bug with JDK 9 b77, JDK 8u51 b16 on MS Windows 7 OS.
17-08-2015

The minimal test case was attached to the bug as "StackOverflowErrorOnPrintDialog.java" file.
17-08-2015