On Fri, 23 Jan 2026 18:26:20 GMT, Phil Race <[email protected]> wrote:
>> src/java.desktop/share/classes/javax/swing/JPopupMenu.java line 957:
>>
>>> 955: if (invoker != null) {
>>> 956: Component oldInvoker = this.invoker;
>>> 957: this.invoker = invoker;
>>
>> This doesn't look right to me. Is `this.invoker == null` an invalid state?
>>
>> I believe the only thing that requires to be guarded by `if (invoker !=
>> null)` is `invoker.addPropertyChangeListener`; maybe `ui.installUI(this)`,
>> however, I can't see why the latter should be skipped in cases where
>> `invoker` is `null`.
>
> I'm also not sure it is right. It changes from an NPE to a no-op.
> Before the previous fix as well as with the current code, null will at least
> do uninstallUI()
> And because of this bug report it seems people expect null to be valid and
> presumably do something.
I did what I did seeing the spec "the component in which the popup menu is to
be displayed" which I construed as the popup menu should be displayed against a
component be in JMenu, JLabel, JToolTip etc and it should not be an orphaned
popupmenu as I was not sure of its usecase [Even the parent bug that popup
doesn't go when component is removed seems to suggest that popup should be tied
to a parent]
but it seems the implementation can expect a orphaned/standalone popup and show
it at set location
https://github.com/openjdk/jdk/blob/cba7d88ca427984ebb27a1634aab10a62c9eede1/src/java.desktop/share/classes/javax/swing/JPopupMenu.java#L996-L1014
so I updated the PR accordingly to maintain a status-quo
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/29377#discussion_r2731136926