Skip to content

Conversation

@prsadhuk
Copy link
Contributor

@prsadhuk prsadhuk commented Dec 5, 2025

SwingUtilities.replaceUIInputMap() and SwingUtilities.replaceUIActionMap() do not actually remove previously installed maps as their Javadoc indicates if null is passed as uiInputMap/uiActionMap

* to <code>uiInputMap</code>. If <code>uiInputMap</code> is {@code null},
* this removes any previously installed UI InputMap.

* to <code>uiActionMap</code>. If <code>uiActionMap</code> is {@code null},
* this removes any previously installed UI ActionMap.

If the passed uiInputMap/uiActionMap is null, JComponent actually doesn't create a fresh map and returns the previously installed map

case WHEN_IN_FOCUSED_WINDOW:
if (getFlag(WIF_INPUTMAP_CREATED)) {
return windowInputMap;
}
// Hasn't been created yet.
if (create) {
ComponentInputMap km = new ComponentInputMap(this);
setInputMap(condition, km);
return km;
}

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.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-6726690: SwingUtilities.replaceUI*Map() methods do not remove previously installed maps (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28671/head:pull/28671
$ git checkout pull/28671

Update a local copy of the PR:
$ git checkout pull/28671
$ git pull https://git.openjdk.org/jdk.git pull/28671/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28671

View PR using the GUI difftool:
$ git pr show -t 28671

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28671.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 5, 2025

👋 Welcome back psadhukhan! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Dec 5, 2025

@prsadhuk This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

6726690: SwingUtilities.replaceUI*Map() methods do not remove previously installed maps

Reviewed-by: azvegint

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 507 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the client client-libs-dev@openjdk.org label Dec 5, 2025
@openjdk
Copy link

openjdk bot commented Dec 5, 2025

@prsadhuk The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 5, 2025
@mlbridge
Copy link

mlbridge bot commented Dec 5, 2025

Webrevs

return;
}
map = parent;
}
if (map != null && uiInputMap == null) {
Copy link
Member

@azvegint azvegint Dec 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 1826 seems to be unreachable, as we have while (map != null) { before in the same method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right..removed..

Comment on lines 56 to 58
// Show the frame
JFrame frame = new JFrame("UIMapTest");
frame.add(button);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this?

Suggested change
// Show the frame
JFrame frame = new JFrame("UIMapTest");
frame.add(button);

In its current state, the test will fail on headless systems because the test does not have the @key headful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

map.put(KeyStroke.getKeyStroke("released ENTER"), "released");

// Add the map
SwingUtilities.replaceUIInputMap(button, JComponent.WHEN_IN_FOCUSED_WINDOW, map);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although the fix changes both replaceUIInputMap and replaceUIActionMap, only replaceUIInputMap is tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ActionMap test added

@@ -1815,6 +1815,9 @@ public static void replaceUIInputMap(JComponent component, int type,
InputMap parent = map.getParent();
if (parent == null || (parent instanceof UIResource)) {
map.setParent(uiInputMap);
if (uiInputMap == null) {
map.clear();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if if (parent == null || (parent instanceof UIResource)) { is false and uiInputMap == null?
Should we also clear the map?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed..

Copy link
Member

@azvegint azvegint left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that testing looks good on all platforms.

Comment on lines 1837 to 1839
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another approach would be to nullify the map.
In this case we don't modify the previously stored map. If a user stores a link to it, they can reuse it later.

Suggested change
if (uiActionMap == null) {
component.setActionMap(null);
return;
}
ActionMap map = component.getActionMap(true);

However, this will also require updating the JComponent code to reset the flags.

public final void setActionMap(ActionMap am) {
actionMap = am;
setFlag(ACTIONMAP_CREATED, true);
}

It may be worth considering this option.

Copy link
Contributor Author

@prsadhuk prsadhuk Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had tried with nullify by using setInputMap(null) initially but there was some CI issue with some tests with that approach so I followed this and with this, the fix is contained in this class.

.JComponent's flag set/reset method is private so any change there possibly would have needed CSR so I guess this is good for this issue..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JComponent's flag set/reset method is private so any change there possibly would have needed CSR so I guess this is good for this issue..

or just change the implementation without changing the specification

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

client client-libs-dev@openjdk.org ready Pull request is ready to be integrated rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

2 participants