RFR: 8334593: Adding, removing and then adding a JFXPanel again leads to NullPointerException

Kevin Rushforth kcr at openjdk.org
Fri Jun 28 14:15:24 UTC 2024


On Fri, 28 Jun 2024 08:49:49 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

> Adding, then removing, and then adding a JFXPanel to the same component in the Swing scene graph leads to a NullPointerException in GlassScene because the sceneState is null.
> Removing JFXPanel calls JFXPanel.removeNotify which calls Window.hide which calls SceneHelper.disposePeer -> Scene.disposePeer -> EmbeddedScene.dispose -> GlassScene.dispose which sets "sceneState" to null...
> so when GlassScene.updateSceneState is called, it results in NPE.
> Fix is to check if `host` (which is usually javafx.embed.swing.JFXPanel$HostContainer for active JFXPanel) has been reset/deleted which is done when `EmbeddedScene.dispose` is called during removeNotify and abstain from updating the scene state

Can you add an automated test to cover this fix?

Worth noting, this won't fully solve the problem that the reporter of this bug filed. The null check will prevent the NPE, but the scene will still not be visible. To allow removing and then re-adding the `JFXPanel`, we would need to not call `Window.hide` when the `JFXPanel` is removed. We should file a follow-on Enhancement to consider doing this, but that will need more discussion. The main point that would need to be solved is to figure out when to call `Window.hide` if not when the `JFXPanel` is  removed.

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

PR Comment: https://git.openjdk.org/jfx/pull/1493#issuecomment-2197030820


More information about the openjfx-dev mailing list