RFR: 8368576: PrintJob.getGraphics() does not specify behavior after PrintJob.end()

Phil Race prr at openjdk.org
Mon Oct 20 20:44:07 UTC 2025


On Sat, 18 Oct 2025 03:11:16 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:

> > It might be useful to mention that, as far as I understand, calling methods on a Graphics object after its target has been disposed is undefined behavior. I hope it does not cause a crash or something.
> 
> still think it is better to specify and test......https://bugs.openjdk.org/browse/JDK-8367702

As you note that other fix (PR here https://github.com/openjdk/jdk/pull/27458/files) already added the test for null.

I don't think we need to specify anything here about use after dispose().
It is the case from the very beginning for all instances of java.awt.Graphics and its sub-classes. 
https://docs.oracle.com/en/java/javase/25/docs/api/java.desktop/java/awt/Graphics.html#dispose()

The other part about not causing a crash. I agree. But that's not related to specification and should be handled separately.
I played around and I did actually get a crash on macOS. I will submit a PR for that very shortly

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

PR Comment: https://git.openjdk.org/jdk/pull/27474#issuecomment-3423650229


More information about the client-libs-dev mailing list