On Sun, 28 Jul 2024 22:25:52 GMT, Phil Race <p...@openjdk.org> wrote:
>> When a printjob is cancelled midway, `PrinterAbortException `was not thrown >> in macos. because >> firstly,` cancelCheck` invokes` LWCToolkit.invokeLater` with null as >> parameter causing it to fail with NPE and >> secondly PrinterAbortException was consumed silently when `printLoop` throws >> any exception >> which is rectified to throw the PrinterAbortException when encountered.. > > src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java line 756: > >> 754: boolean cancelled = (performingPrinting && userCancelled); >> 755: if (cancelled) { >> 756: cancelDoc(); > > The comments about deadlock refer to isCancelled() but is that not also why > there was an invokeLater() ? > It is not at all clear to me. Perhaps you can explain how the deadlock would > occur and why it is not a problem for calling cancelDoc() ? This comment was there from initial macosx port. Since RasterPrinterJob.`isCancelled` relies on `synchronized` block and since this `cancelCheck` method was called from native, it might have been suspected that it might block the native AppKit thread, so `invokeLater` was added. But the problem was `LWCToolkit.invokeLater` is called with `null` argument, which was not a problem in initial macosx port but [JDK-8042087](https://bugs.openjdk.org/browse/JDK-8042087) got it modified in jdk9 to throw an exception if component argument is null, which is the case in `CPrinterJob.m#cancelCheck` > LWCToolkit.inokeAndWait is called on the Appkit thread, but if the component > argument is null it uses EventQueue.invokeLater which would fail with an NPE > in plugin mode. The method should be updated to throw an exception in case > the provided component is null. Coming to your question, I guess if there is a deadlock, calling `cancelDoc` directly will also face the same issue as it also relies on same `synchronized(this)` block but I could not find any deadlock issue with the printing for which this `invokeLater` safeguard was added... So, Is the above comment " fail with an NPE in plugin mode" still applicable i.e do we still support plugin mode? If not, we can restore invokeLater call in this code and use `Toolkit.getToolkit` if the component is null as it was[ previously to JDK-8042087 ](https://github.com/openjdk/jdk/commit/bb2698cfa6f2bdc92c197f17a7d2f90003db05fa) ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/20027#discussion_r1694942392