JDK-8165098 : WebEngine.print will attempt to print even if the printer job is complete or has an error
  • Type: Bug
  • Component: javafx
  • Sub-Component: web
  • Affected Version: 8,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-08-30
  • Updated: 2017-09-07
  • Resolved: 2016-09-29
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.
8u131Fixed 9Fixed
Related Reports
Relates :  
Relates :  
This is a Development managed bug. Further details will be added later.
Changeset: f5bdcd0e4b64 Author: kcr Date: 2016-09-29 05:57 -0700 URL: http://hg.openjdk.java.net/openjfx/9-dev/rt/rev/f5bdcd0e4b64 8150982: Crash when calling WebEngine.print on background thread 8165098: WebEngine.print will attempt to print even if the printer job is complete or has an error Summary: Perform beginPrinting and endPrinting on correct thread; check for errors in print method Reviewed-by: prr, ghb

After discussion with Phil we are combining this fix with the fix for JDK-8150982. The combined fix is reviewed in the other bug.

Kevin already has a patch for the threading. It just needs to be posted. The error checking should be included since together they amount to a 90% rewrite of the same method. Some pseudo-code for this is pasted here. The actual fix needs to create a FutureTask .. private static final boolean statusOK(PrinterJob job) { PrinterJob.Status s = job.getStatus(); return (s == PrinterJob.Status.NOT_STARTED) || (s == PrinterJob.Status.PRINTING); } /** * Prints the current Web page using the given printer job. * <p>This method does not modify the state of the job, nor does it call * {@link PrinterJob#endJob}, so the job may be safely reused afterwards. * * @param job printer job used for printing * @since JavaFX 8.0 */ public void print(PrinterJob job) { if (!statusOK(job)) { return; } PageLayout pl = job.getJobSettings().getPageLayout(); float width = (float) pl.getPrintableWidth(); float height = (float) pl.getPrintableHeight(); int pageCount = invokeOnFXThreadAndWait(page.beginPrinting(width, height)); for (int i = 0; i < pageCount; i++) { while (statusOK(job)) { Node printable = new Printable(page, i, width); // what about this one ? job.printPage(printable); } } invokeOnFXThreadAndWait(page.endPrinting()); } } As an aside I noticed that the iOS and Android versions of this class are missing this API. That is another issue but also needs to be addressed.

It hasn't been tested yet, but I am fairly certain that it would affect all 8u releases.

Does it affect 8u102?