JDK-8067059 : PrinterJob.pageDialog() with DialogSelectionType.NATIVE returns a PageFormat when cancelled.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 8,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2014-12-09
  • 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
Description
PrinterJob.pageDialog() with DialogSelectionType.NATIVE returns a PageFormat when cancelled
it should per spec. return null. This bug is seen on Windows.
Comments
This really should be backported to 8u ...
30-07-2016

The issue was if we "cancel" Printer Job setup dialog which has been created with DialogSelectionType.NATIVE it should return "null" as per spec https://docs.oracle.com/javase/8/docs/api/java/awt/print/PrinterJob.html#pageDialog-javax.print.attribute.PrintRequestAttributeSet- [If the user cancels the dialog, the attributes will not reflect any changes made by the user, and the return value will be null.] We were returning PageFormat instead. As per spec, pageDialog(PageFormat page) will return "the original page object if the dialog is cancelled, or a new PageFormat object containing the format indicated by the user if the dialog is acknowledged" If it is returning the same object, it means user has pressed cancel on print dialog. We check pageDialog(PageFormat) returns the same PageFormat object or not. If it is, then return null to conform with spec.
16-11-2015

Note that this is applicable to JDK 8+ only. With JDK 7 and below the pageDialog ignores the NATIVE attribute and shows the Swing dialog and behaves per spec. So this is not a regression as such, although apps that were pointlessly but harmlessly adding this to the attribute set might be surprised.
09-12-2014

This was reported via FX bug https://javafx-jira.kenai.com/browse/RT-39628 but the problem is as follows :- Try the following and "cancel" all dialogs. Without NATIVE the "attribute set" case returns null, with the addition of DialogTypeSelection.NATIVE it returns a PageFormat which should only happen in the case which takes a PageFormat. import java.awt.*; import java.awt.print.*; import javax.print.*; import javax.print.attribute.*; import javax.print.attribute.standard.*; class PageDlgApp { public static void main(java.lang.String[] args) { PrinterJob pj = PrinterJob.getPrinterJob(); System.out.println(pj.pageDialog(pj.defaultPage())); PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet(); System.out.println(pj.pageDialog(pSet)); pSet.add(DialogTypeSelection.NATIVE); System.out.println(pj.pageDialog(pSet)); } } java PageDlgApp java.awt.print.PageFormat@568db2f2 null java.awt.print.PageFormat@3fa77460
09-12-2014