RFR: 8376492: NullPointer in ContextMenu sub-menu when graphic and style classes are changed while the menu is open [v2]

Andy Goryachev angorya at openjdk.org
Tue Feb 24 20:46:56 UTC 2026


On Mon, 23 Feb 2026 16:18:47 GMT, Dmitry Markov <dmarkov at openjdk.org> wrote:

>> A NullPointerException occurs when a ContextMenu submenu is opened for the second time and the graphic and style classes are modified while the menu is open.
>> 
>> Fix: Added a null check.
>
> Dmitry Markov has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Remove previous ItemStyleClassListener

The idea of storing listener instances in the `Node's` properties map used by the original designer looks totally wrong to me, but is definitely out of scope for this PR.

This fix does provide a good solution, resolving an NPE and a memory leak - at least I cannot see any issues using an updated reproducer

https://github.com/andy-goryachev-oracle/Test/blob/main/src/goryachev/bugs/ContextMenu_SubMenuNPE_8376492.java

(pressing any key updates styles and graphic in both menus)

I would have still preferred to extract the `MenuLabel` into a separate function to remove the dependency on the `MenuItemContainer.label` , but the latest code change makes this scenario impossible, as far as I can tell.

The fix looks innocent enough, I think one reviewer might be sufficient.

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

Marked as reviewed by angorya (Reviewer).

PR Review: https://git.openjdk.org/jfx/pull/2075#pullrequestreview-3850411659
PR Comment: https://git.openjdk.org/jfx/pull/2075#issuecomment-3954630147


More information about the openjfx-dev mailing list