JDK-4374956 : Toolkit.getPrintJob incorrectly throws HeadlessException in headless mode
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_7
  • CPU: sparc
  • Submitted: 2000-09-28
  • Updated: 2000-12-07
  • Resolved: 2000-11-21
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.
Other
1.4.0 betaFixed
Related Reports
Relates :  
Relates :  
Description
With this code:


   Toolkit tk = Toolkit.getDefaultToolkit();
   JobAttributes  ja = new JobAttributes(); // getDialog == JobAttributes.DialogType.NONE
   PageAttributes pa = new PageAttributes();

   ja.setDestination(JobAttributes.DestinationType.FILE);
   ja.setFileName("jn-resolution");
   ja.setDialog(JobAttributes.DialogType.NONE);

   PrintJob pj = tk.getPrintJob(null, "finalize", ja, pa);

I get the following exception

  java.awt.HeadlessException
        at sun.awt.motif.PSPrinterJob.printDialog(PSPrinterJob.java:507)
        at sun.java2d.PrintJob2D.printDialog(PrintJob2D.java:103)
        at sun.awt.motif.MToolkit.getPrintJob(MToolkit.java:364)
        at sun.awt.HeadlessToolkit.getPrintJob(HeadlessToolkit.java:341)
        at java_awt_PrintJob.do_getGraphics_1(java_awt_PrintJob.java:66) <--- tk.getPrintJob above.
        at java_awt_PrintJob.run(java_awt_PrintJob.java:300)
        at headless.bat.BATRunner.doTestForClass(BATRunner.java:34)
        at headless.bat.BATRunner.doTestCases(BATRunner.java:46)
        at test.run(test.java:6)
        at java.lang.Thread.run(Thread.java:488)

According to the javadoc, setting DialogType.NONE will avoid the throwing of HeadlessException.

See attached .tar file for the full test case.

============================

the headless spec has been updated to indicate that PrintJob is not
supported in that mode

phil.race@eng 2000-11-15
=======================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: merlin-beta FIXED IN: merlin-beta INTEGRATED IN: merlin-beta VERIFIED IN: merlin-beta
14-06-2004

SUGGESTED FIX > *** 898,906 **** > * JobAttributes.DialogType.NATIVE. > * @throws IllegalArgumentException if pageAttributes specifies differing > * cross feed and feed resolutions. This exception is always > ! * thrown when GraphicsEnvironment.isHeadless() returns true > ! * (frame is null) and jobAttributes.getDialog() is anything > ! * but JobAttributes.DialogType.NONE. > * @throws SecurityException if this thread is not allowed to initiate a > * print job request, or if jobAttributes specifies print to file, > * and this thread is not allowed to access the file system > --- 898,904 ---- > * JobAttributes.DialogType.NATIVE. > * @throws IllegalArgumentException if pageAttributes specifies differing > * cross feed and feed resolutions. This exception is always > ! * thrown when GraphicsEnvironment.isHeadless() returns true. > * @throws SecurityException if this thread is not allowed to initiate a > * print job request, or if jobAttributes specifies print to file, > * and this thread is not allowed to access the file system > *************** > *** 914,919 **** > --- 912,921 ---- > public PrintJob getPrintJob(Frame frame, String jobtitle, > JobAttributes jobAttributes, > PageAttributes pageAttributes) { > + > + if (GraphicsEnvironment.isHeadless()) { > + throw new IllegalArgumentException(); > + } > // Override to add printing support with new job/page control classes > if (this != Toolkit.getDefaultToolkit()) { > return Toolkit.getDefaultToolkit().getPrintJob(frame, jobtitle,
11-06-2004

EVALUATION Closing this out as a duplicate of 4285177. michael.martak@Eng 2000-10-03 Reopened, and reassigning to 2D. michael.martak@Eng 2000-10-04 =========== There' no intention of supporting Toolkit.getPrintJob in headless mode in the merlin release. The headless spec should not be saying this would work and it needs to be amended on Toolkit.getPrintJob to say that an exception is always thrown in headless mode. phil.race@eng 2000-11-08 ========================
08-11-2000