JDK-8039412 : Stack overflow on Linux using DialogTypeSelection.NATIVE
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 8,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2014-04-07
  • Updated: 2017-11-29
  • Resolved: 2015-11-17
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 8 JDK 9
8u152Fixed 9 b96Fixed
Related Reports
Duplicate :  
Description
This program shows a stack over flow ..
import java.awt.print.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;

public class PD {

    public static void main(String args[]) {
       PrinterJob job = PrinterJob.getPrinterJob();
       if (job == null) {
           return;
       }
       PrintRequestAttributeSet pSet =
            new HashPrintRequestAttributeSet();
       pSet.add(DialogTypeSelection.NATIVE);
       job.printDialog(pSet);
       job.pageDialog(pSet);
   }
}

Exception in thread "main" java.lang.StackOverflowError
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.print.RasterPrinterJob.pageDialog(RasterPrinterJob.java:720)
	at sun.print.RasterPrinterJob.pageDialog(RasterPrinterJob.java:762)
	at sun.print.RasterPrinterJob.pageDialog(RasterPrinterJob.java:737)
	at sun.print.RasterPrinterJob.pageDialog(RasterPrinterJob.java:762)
	at sun.print.RasterPrinterJob.pageDialog(RasterPrinterJob.java:737)



Comments
The cause of the bug was as mentioned above by Phil. Basically, if DialogTypeSelection.NATIVE attribute is selected, RasterPrinterJob.pageDialog(attributes) was calling RasterPrinterJob.pageDialog(pageformat) which again calls RasterPrinterJob.pageDialog(attributes) which calls pageDialog(pageformat) and so on resulting in recursion. The fix is to check in pageDialog(PageFormat) if it is DialogTypeSelection.NATIVE and remove this attribute temporarily before calling pageDialog(attributes) and restore the DialogTypeSelection.NATIVE after the call This will ensure 2nd time pageDialog(attributes) is called, the NATIVE selection is not present so it will avoid recursion.
13-11-2015

JDK on Linux uses the same dialog whether NATIVE is specified or not. Most platforms have a platform subclass which accepts a page format and that is used for native. However on Linux the one that accepts a page format calls the one that uses an attribute set. Since that second one has the cross-platform code that detects the NATIVE request this ends up calling into the page format one. However since the attributes used to call the page format one are those supplied by the app to the pageDialog call they are not yet installed on the job. That only happens when the printDIalog is shown. So in the pagedialog shown first case the 2nd call to pageDialog(AttributeSet) doesn't contain the native selection any more. But once its on the job then we will get the recursion. This wasn't an issue before JDK 8 since the page dialog did not previously support NATIVE. Ironically that was fixed for FX .. which is where we are seeing this issue manifest on Linux. Need to look into the right way to handle this.
07-04-2014