-
Notifications
You must be signed in to change notification settings - Fork 6.2k
6726690: SwingUtilities.replaceUI*Map() methods do not remove previously installed maps #28671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…sly installed maps
|
👋 Welcome back psadhukhan! A progress list of the required criteria for merging this PR into |
|
@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: 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
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 |
Webrevs
|
| return; | ||
| } | ||
| map = parent; | ||
| } | ||
| if (map != null && uiInputMap == null) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right..removed..
| // Show the frame | ||
| JFrame frame = new JFrame("UIMapTest"); | ||
| frame.add(button); |
There was a problem hiding this comment.
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?
| // 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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); | |||
| } | |||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed..
azvegint
left a comment
There was a problem hiding this 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.
There was a problem hiding this comment.
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.
| 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.
jdk/src/java.desktop/share/classes/javax/swing/JComponent.java
Lines 2524 to 2527 in cba09cd
| public final void setActionMap(ActionMap am) { | |
| actionMap = am; | |
| setFlag(ACTIONMAP_CREATED, true); | |
| } |
It may be worth considering this option.
There was a problem hiding this comment.
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..
There was a problem hiding this comment.
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
SwingUtilities.replaceUIInputMap()andSwingUtilities.replaceUIActionMap()do not actually remove previously installed maps as their Javadoc indicates ifnullis passed asuiInputMap/uiActionMapjdk/src/java.desktop/share/classes/javax/swing/SwingUtilities.java
Lines 1802 to 1803 in 7e91d34
jdk/src/java.desktop/share/classes/javax/swing/SwingUtilities.java
Lines 1827 to 1828 in 7e91d34
If the passed
uiInputMap/uiActionMapis null,JComponentactually doesn't create a fresh map and returns the previously installed mapjdk/src/java.desktop/share/classes/javax/swing/JComponent.java
Lines 2586 to 2595 in 7e91d34
which is in contradiction to the
replaceUI*Mapspec soSwingUtilitiesneeds to clear the previously installed map which is being done in this fix.Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28671/head:pull/28671$ git checkout pull/28671Update a local copy of the PR:
$ git checkout pull/28671$ git pull https://git.openjdk.org/jdk.git pull/28671/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 28671View PR using the GUI difftool:
$ git pr show -t 28671Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28671.diff
Using Webrev
Link to Webrev Comment