On Mon, 1 Jul 2024 09:16:52 GMT, Prasanta Sadhukhan <psadhuk...@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
>
> Prasanta Sadhukhan has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Test fix

tests/system/src/test/java/test/javafx/embed/swing/JFXPanelNPETest.java line 
106:

> 104:                 frame.remove(fxPanel);
> 105:                 // fxPanel added to frame again
> 106:                 frame.add(fxPanel); // <-- leads to NullPointerException

You can use JUnit5 to write this test (class) and use `assertDoesNotThrow(() -> 
frame.add(fxPanel));`, which makes this a bit better to understand

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

PR Review Comment: https://git.openjdk.org/jfx/pull/1493#discussion_r1661580655

Reply via email to