RFR: 8370141: [macOS] Crash after PrinterJob ends when Graphics.create() is used.

Phil Race prr at openjdk.org
Tue Oct 21 18:22:18 UTC 2025


On Tue, 21 Oct 2025 17:29:28 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:

>> macOS printing uses a Quartz surface. It is the SurfaceData for a CPrinterGraphics.
>> That Surface is not disconnected from the graphics unless Graphics.dispose() is called.
>> If the application uses Graphics.create() then the implementation will not Graphics.dispose() it.
>> If it is used after printing is complete and the CGContext is no longer valid a crash will occur.
>> We need to invalidate the surface as soon as printing to a page is done.
>> Note: this is Graphics.dispose(), and is unrelated to disposal of an object when it becomes unreachable.
>
> src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java line 833:
> 
>> 831:                 }
>> 832:                 painter.print(pathGraphics, FlipPageFormat.getOriginal(page), pageIndex);
>> 833:                 delegate.surfaceData.invalidate();
> 
> how this code synchronized? is it always executed on EDT?

I don't know where you are headed. All it does is set a boolean variable and there's no reason to be on the EDT.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/27905#discussion_r2449292645


More information about the client-libs-dev mailing list