JDK-6357885 : PrinterJob.getPrinterJob().printDialog() causes IllegalArgumentException when print spooler is off
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 5.0,6u10
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-12-01
  • Updated: 2011-03-08
  • Resolved: 2011-03-08
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 7
7 b17Fixed
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Windows XP service pack 2 and 2000 service pack 4

EXTRA RELEVANT SYSTEM CONFIGURATION :
The print spooler service is turned off.

A DESCRIPTION OF THE PROBLEM :
When the print spooler service is turned off and a java application calls PrinterJob.getPrinterJob().printDialog() an error occurs that cannot be caught and handled and the current thread locks up.

This may occur under other scenarios that I have not tested such as if a printer is not installed but I have not checked.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Turn off the Print Spooler service in Control Panel -> Administrative Tools -> Services

Run the example code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
In Java 1.4.2_06 a dialog is displayed to the user with the following message:
Printing Error
Before you can print you must install a printer.
  To do this click ... etc
ACTUAL -
The thread that calls the printDialog() method locks up.
When using this code from an applet the applet GUI was left in an unstable state, e.g. Could not press buttons with the mouse.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "Thread-2" java.lang.IllegalArgumentException: Invalid value for property printer or null printer port
	at sun.awt.windows.WPrintDialogPeer._show(Native Method)
	at sun.awt.windows.WPrintDialogPeer.access$000(WPrintDialogPeer.java:14)
	at sun.awt.windows.WPrintDialogPeer$1.run(WPrintDialogPeer.java:44)
	at java.lang.Thread.run(Thread.java:595)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public static void main(String[] args)
{
	java.awt.print.PrinterJob.getPrinterJob().printDialog();
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Turn on the Print Spooler service in Control Panel -> Administrative Tools -> Services

Comments
EVALUATION Turning off the spooler is an unusual thing to do, but we should still fix this. awt_PrintControl.cpp's InitPrintDialog method throws the IAE. I think it should instead just return FALSE, as no caller is prepared to deal with that. As a matter of robustness, I think the code that shows the peers need to catch any exception. Failing to do so means hide() isn't called. Also in 1.5 FCS and right up to 1.7 b14 in most code paths, we don't reach that IAE because WPrinterJob.getPrintService() trys to set the native service to the value of the default printer. This fails in a call to CreateDC("WINSPOOL", ..) because the spooler is off. The failure results in PrinterException being thrown. That made sense in the original context of this code where it was meant to be used by the public API PrinterJob.setPrintService() which does declare it throws PrinterException. But in this case the native method is used directly from a context that doesn't declare or expect the exception. We should add a throws clause to the native method declaration and then the caller needs to be updated to absorb this.
22-06-2007