RFR: 8335231: [macos] Test java/awt/print/PrinterJob/Cancel/PrinterJobCancel.java failed on macOS because the case didn't get the expected PrintAbortException [v2]
Prasanta Sadhukhan
psadhukhan at openjdk.org
Tue Jul 30 08:10:32 UTC 2024
On Mon, 29 Jul 2024 09:56:17 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:
>> 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)
I dont see any deadlock in my testing so I am using `isCancelled` .
How do you normally "cancel" ongoing printing in macosx? I tried clicking on "x" in "Print Centre" when the specific print job is shown in the printer spooler and I dont see any deadlock for long printing tests like PrintAllFonts etc..
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20027#discussion_r1696516561
More information about the client-libs-dev
mailing list