RFR: 8303740 JavaFX - Leak in Logging, Logging remembers last exception

John Hendrikx jhendrikx at openjdk.org
Tue Mar 7 13:22:10 UTC 2023


On Tue, 7 Mar 2023 11:59:20 GMT, Florian Kirmaier <fkirmaier at openjdk.org> wrote:

> When an exception is logged in JavaFX, then the exception is kept in a reference.
> This way, always the last logged exception is retained.
> 
> This is a memory-leak.
> This was done to write unit-tests to ensure certain error-cases are logged.
> 
> A simple fix is, to add a flag, to enable/disable retaining the exception.

Well...  I'm quite surprised to see code testing for log messages -- its a very bad practice.  The side effects should be testable with or without the message (ie, if something throws NPE, the old value is restored or not modified, etc).  I doubt the log messages are part of any contract that JavaFX specifies.  But anyway...

I noticed though that the `check` method only checks the class, yet the entire exception is stored.  Storing only the class would also alleviate this issue, although it could still prevent class unloading then.

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

PR: https://git.openjdk.org/jfx/pull/1053


More information about the openjfx-dev mailing list