|
Description
|
J2SE Version (please include all output from java -version flag):
Source code problem
jdk-6-rc-src-b98-jrl-01_sep_2006.jar
Does this problem occur on J2SE 1.4.x or 5.0.x ? Yes / No (pick one)
Yes, 5.0_08. Did not test earlier releases
Operating System Configuration Information (be specific):
Windows XP
Bug Description:
Poor exception handling in RasterPrinterJob and Win32PrintJob
sun.print.RasterPrinterJob hides exceptions
Any exception that is thrown when getting the printable is caught by printPage() and discarded. The initCause of the PrinterException is not set, thus loosing the exception for customer .
We have a check that we cannot make until the printing process has started. If this check fails, we throw an exception to stop the printing. However, this exception is *completely* lost with no chance of detection except by circumventing the normal exception handling mechanism.
I would recommend setting the initCause of the PrinterException so that error handling routines can identify the causes of exceptions and inform the user accordingly.
Furthermore, this makes it a lot more difficult to debug printing since the original exception is lost without any indication of what it was. Knowing this is the implementation, once could create a proxy class around the 'document' customer to display any errors that occur, but this should not be necessary.
Next, pageableJob() in sun.print.Win32PrintJob sets the printReturned variable to true, which has the effect of making the print job uncancelable. So, if our job throws an exception, we cannot cancel the job to keep in from printing any part that might have already succeeded. I am not sure why it is just not canceled automatically (since the user will undoubtedly try again), but regardless of that decision, it should not prevent the programmer from being able to cancel on behalf of the user when it makes sense.
sun.print.RasterPrinterJob.java
protected int printPage(Pageable document, int pageIndex)
throws PrinterException
{
PageFormat page;
PageFormat origPage;
Printable painter;
try {
origPage = document.getPageFormat(pageIndex);
page = (PageFormat)origPage.clone();
painter = document.getPrintable(pageIndex);
} catch (Exception e) {
throw new PrinterException("No page or printable exists.");
}
sun.print.Win32PrintJob
public void pageableJob(Pageable pageable) throws PrintException {
try {
synchronized(this) {
if (job != null) { // shouldn't happen
throw new PrintException("already printing");
} else {
job = new sun.awt.windows.WPrinterJob();
}
}
PrintService svc = getPrintService();
job.setPrintService(svc);
if (copies == 0) {
Copies c = (Copies)svc.getDefaultAttributeValue(Copies.class);
copies = c.getValue();
}
job.setCopies(copies);
job.setJobName(jobName);
job.setPageable(pageable);
job.print(reqAttrSet);
notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
return;
} catch (PrinterException pe) {
notifyEvent(PrintJobEvent.JOB_FAILED);
throw new PrintException(pe);
} finally {
printReturned = true;
notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
}
}
public void cancel() throws PrintException {
synchronized (this) {
if (!printing) {
throw new PrintException("Job is not yet submitted.");
} else if (job != null && !printReturned) {
job.cancel();
notifyEvent(PrintJobEvent.JOB_CANCELED);
return;
} else {
throw new PrintException("Job could not be cancelled.");
}
}
}
Steps to Reproduce (be specific):
Any exception thrown be getPrintable() is lost an replaced by a generic one.
Posted Date : 2006-09-06 00:27:14.0
|