On Tue, 24 Nov 2026 08:12:23 GMT, Prasanta Sadhukhan <[email protected]> wrote:
> JDK-6726690 fixed the issue whereby > >> SwingUtilities.replaceUIInputMap() and SwingUtilities.replaceUIActionMap() >> were not actually removing/uninstalling previously installed maps >> contrary to what their Javadoc indicates, if null is passed as >> uiInputMap/uiActionMap > > by adding map.clear() to the traversal whenever the replacement argument was > null. > So, the old bindings were erased, however, it turned out it also deleted > bindings belonging to the application. > > Basically, map traversal starts at the component’s own application map so > consequently, the new clearing operation deletes application entries _before_ > reaching the UI-owned parent. > > The methods have no information that a particular entry belongs to the > application; so map.clear() simply clears whichever map it is currently > visiting. > This becomes a regression because Swing itself calls these removal methods > `replaceUIInputMap()`, `replaceUIActionMap()` during normal UI changes. > When `updateComponentTreeUI()` updates a component, Swing uninstalls its old > UI delegate and installs the current look-and-feel delegate. > During uninstallation, delegates remove their keyboard bindings by calling > `replaceUIInputMap(..., null)` and `replaceUIActionMap(..., null)`. > With unconditional clearing, those cleanup calls erase application shortcuts > too. > That is the failure reported here. > > This patch introduces a temporary record of which components are undergoing > UI installation or uninstallation > The existing callback calls in JComponent go through newly added helper > methods in SwingUtilities2. > Before installing or uninstalling the component’s look-and-feel > implementation, > `installUI()` records which component is being updated. > After the operation finishes, `changeUI()` restores the previous record. > ` isChangingUI()` then consult that record before clearing a map, that is, > checks whether the component has an active UI-change context. > `SwingUtilities.replaceUIInputMap()` and `replaceUIActionMap()` use this to > decide whether to skip map.clear(). > > So, basically, when `updateComponentTreeUI()` installs or uninstalls a > component’s look-and-feel implementation, the helper marks that component as > being updated and if the look-and-feel code requests removal of its UI maps > during this process, the replacement methods skip clearing the maps. This > preserves the application’s custom key bindings > The explicit removal calls in the JDK-6726690 test occur when no such update > is in progress. The replacement methods... It looks like two `JList` paths are not covered, and can still clear application key bindings: - Under Nimbus LaF, changing [`Nimbus.Overrides`](https://download.java.net/java/early_access/genzgc/docs/api/java.desktop/javax/swing/plaf/nimbus/NimbusStyle.html) reinstalls keyboard actions outside of `setUI()`. This clears the list’s `WHEN_FOCUSED` bindings and its application actions. - `JList.writeObject()` calls `ui.installUI(this)` directly during serialization. If `List.focusInputMap` is absent, `BasicListUI` can clear the `WHEN_FOCUSED` bindings on the original list. ------------- PR Review: https://git.openjdk.org/jdk/pull/34034#pullrequestreview-6079855328
