RFR: 6726690: SwingUtilities.replaceUI*Map() methods do not remove previously installed maps
Alexander Zvegintsev
azvegint at openjdk.org
Mon Dec 8 11:08:05 UTC 2025
On Fri, 5 Dec 2025 03:01:05 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:
> `SwingUtilities.replaceUIInputMap()` and `SwingUtilities.replaceUIActionMap()` do not actually remove previously installed maps as their Javadoc indicates if `null` is passed as `uiInputMap`/`uiActionMap`
>
> https://github.com/openjdk/jdk/blob/7e91d34f3e83b4c39d6ce5de34373d7d74d54512/src/java.desktop/share/classes/javax/swing/SwingUtilities.java#L1802-L1803
> https://github.com/openjdk/jdk/blob/7e91d34f3e83b4c39d6ce5de34373d7d74d54512/src/java.desktop/share/classes/javax/swing/SwingUtilities.java#L1827-L1828
>
> If the passed `uiInputMap`/`uiActionMap` is null, `JComponent` actually doesn't create a fresh map and returns the previously installed map
> https://github.com/openjdk/jdk/blob/7e91d34f3e83b4c39d6ce5de34373d7d74d54512/src/java.desktop/share/classes/javax/swing/JComponent.java#L2586-L2595
> which is in contradiction to the `replaceUI*Map` spec so `SwingUtilities `needs to clear the previously installed map which is being done in this fix.
src/java.desktop/share/classes/javax/swing/SwingUtilities.java line 1825:
> 1823: map = parent;
> 1824: }
> 1825: if (map != null && uiInputMap == null) {
Line 1826 seems to be unreachable, as we have `while (map != null) {` before in the same method.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28671#discussion_r2598163851
More information about the client-libs-dev
mailing list