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

Sergey Bylokhov serb at openjdk.org
Tue Oct 21 17:32:09 UTC 2025


On Mon, 20 Oct 2025 20:45:47 GMT, Phil Race <prr 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?

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

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


More information about the client-libs-dev mailing list