Skip to content
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

8296409: Multiple copies of accelerator change listeners are added to MenuItems, but only 1 is removed #937

Closed
wants to merge 4 commits into from

Conversation

DeanWookey
Copy link
Contributor

@DeanWookey DeanWookey commented Nov 4, 2022

When menu buttons are added and removed from the scene, an accelerator change listener is added to each menu item in the menu. There is nothing stopping the same change listener being added multiple times.

MenuButtonSkinBase calls the ControlAcceleratorSupport.addAcceleratorsIntoScene(getSkinnable().getItems(), getSkinnable()); method each time the button is added to the scene, but that method itself also registers a listener to call itself. Each time the button is added to the scene, the method is called at least twice.

When it's removed from the scene, the remove accelerator method is also called twice, but only the first call removes a change listener attached to the accelerator because the first call removes the entry from the hashmap changeListenerMap. The second call finds nothing in the map, and doesn't remove the additional instance.

This pull request just removes the redundant code in the MenuButtonSkinBase.


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-8296409: Multiple copies of accelerator change listeners are added to MenuItems, but only 1 is removed

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 937

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/937.diff

@DeanWookey DeanWookey changed the title 8296409: Stop additional change listeners being added 8296409: Multiple copies of accelerator change listeners are added to MenuItems, but only 1 is removed Nov 4, 2022
@bridgekeeper
Copy link

bridgekeeper bot commented Nov 4, 2022

👋 Welcome back dwookey! 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 openjdk bot added the rfr Ready for review label Nov 4, 2022
@mlbridge
Copy link

mlbridge bot commented Nov 4, 2022

Webrevs

@andy-goryachev-oracle
Copy link
Contributor

andy-goryachev-oracle commented Nov 4, 2022

I wonder if changes in JDK-8295426: MenuButtonSkin: memory leak when changing skin would impact this PR or vice versa.

PR: #919

@andy-goryachev-oracle
Copy link
Contributor

@DeanWookey : the newly added test still fails with JDK-8295426 changes, so I think we might want to address/integrate this PR first.

@kevinrushforth
Copy link
Member

Reviewers: @arapte @andy-goryachev-oracle


List<Mnemonic> mnemonics = new ArrayList<>();
sceneChangeListener = (scene, oldValue, newValue) -> {
if (oldValue != null) {
ControlAcceleratorSupport.removeAcceleratorsFromScene(getSkinnable().getItems(), oldValue);
Copy link
Contributor

Choose a reason for hiding this comment

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

will it handle a case where the menu button gets attached to a different scene?
could you add a second test for this scenario please?

And i wonder if the problem is in ControlAcceleratorSupport rather than here. We do have a similar code in Control:380, do we have a problem there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code in ControlAcceleratorSupport adds its own scene listeners for each node added. MenuButtonSkinBase does the same, unlike Control which only calls it once.

I think we could fix it in ControlAcceleratorSupport alternatively or in addition to this fix. The code in ControlAcceleratorSupport appears to do everything this would've done.

I've added the test for changing scenes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is an alternative fix: 80971d8
I just reverted the MenuButtonSkinBase changes. The tests pass with this fix, or with both.

I'm a little more nervous about that one because I had to remove the code that removed and then added a scene listener. I'm not sure why it was done because the listener is independent of a specific scene.

Basically, that fix only does the install if the install wasn't already done on that anchor meaning it can get called any number of times safely stopping duplicate accelerators being added.

I would go with either both fixes together, or just the MenuButtonSkinBase one.

Copy link
Contributor

Choose a reason for hiding this comment

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

please forgive me - it might take me a bit longer to review.

@DeanWookey DeanWookey requested review from andy-goryachev-oracle and removed request for arapte November 8, 2022 10:08
@DeanWookey
Copy link
Contributor Author

@kevinrushforth, @arapte I clicked the request review on andy and it removed arapte for some reason. I guess that button shouldn't be clicked. Oops.

@kevinrushforth
Copy link
Member

I clicked the request review on andy and it removed arapte for some reason. I guess that button shouldn't be clicked. Oops.

That seems like a GitHub UI problem. I'll re-request a review from @arapte

@kevinrushforth kevinrushforth requested review from arapte and removed request for andy-goryachev-oracle November 8, 2022 13:04
@andy-goryachev-oracle
Copy link
Contributor

andy-goryachev-oracle commented Nov 30, 2022

@DeanWookey :
Would it be possible to modify this PR to use the alternative solution 80971d8 ? I think the code in this PR as it stands right now removes a bit of functionality that is needed, while the alternative does not.

Also, would it be possible to base your changes on top of #919 since the skin got reworked to eliminate a memory leak, and it might be easier to base your changes on top of that rather than try to resolve non-trivial merge conflicts.

What do you think?

Copy link
Contributor

@andy-goryachev-oracle andy-goryachev-oracle left a comment

Choose a reason for hiding this comment

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

change requested:

@kevinrushforth
Copy link
Member

base on top of #919

Doing this makes it harder for reviewers to see what is actually being changed. Unless / until we enable the Skara support for dependent PRs (which the jdk repo enables, but so far we haven't), I would probably just recommend waiting on the final review until after the dependent PR, #919 in this case, is integrated and then merge master at that time.

@andy-goryachev-oracle
Copy link
Contributor

andy-goryachev-oracle commented Nov 30, 2022

Doing this makes it harder for reviewers to see what is actually being changed.

This is true, but it will the actual review process (especially, testing) move faster. Or, we can wait for #919 to get integrated first.

edit: I want to avoid non-trivial merges, they are harder to deal with than just ignoring changes from another PR.

@kevinrushforth
Copy link
Member

Probably better to just wait then.

@arapte
Copy link
Member

arapte commented Dec 6, 2022

Now that #919 is integrated, the conflict needs to be resolved.

# Conflicts:
#	modules/javafx.controls/src/main/java/javafx/scene/control/skin/MenuButtonSkinBase.java
@DeanWookey
Copy link
Contributor Author

I've put the alternative fix in on top of the latest changes. Sorry it took so long.

Copy link
Contributor

@andy-goryachev-oracle andy-goryachev-oracle left a comment

Choose a reason for hiding this comment

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

looks much leaner now, thanks!

@openjdk
Copy link

openjdk bot commented Dec 15, 2022

@DeanWookey 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:

8296409: Multiple copies of accelerator change listeners are added to MenuItems, but only 1 is removed

Reviewed-by: angorya, arapte

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 7 new commits pushed to the master branch:

  • ae86ed3: 8297067: Update Gradle to 7.6
  • 30147d2: 8298496: IconifyTest fails intermittently on Linux
  • 58376eb: 8187145: (Tree)TableView with null selectionModel: throws NPE on sorting
  • adfc022: 8290040: Provide simplified deterministic way to manage listeners
  • f217d5e: 8298200: Clean up raw type warnings in javafx.beans.property.* and com.sun.javafx.property.*
  • 8763e8b: 8190411: NPE in SliderSkin:140 if Slider.Tooltip.autohide is true
  • dadfcaf: 8295339: DatePicker updates its value property with wrong date when dialog closes

Please see this link for an up-to-date comparison between the source branch of this pull request and 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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@andy-goryachev-oracle, @arapte) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Ready to be integrated label Dec 15, 2022
@DeanWookey
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Ready to sponsor label Dec 19, 2022
@openjdk
Copy link

openjdk bot commented Dec 19, 2022

@DeanWookey
Your change (at version e934696) is now ready to be sponsored by a Committer.

@arapte
Copy link
Member

arapte commented Dec 19, 2022

/sponsor

@openjdk
Copy link

openjdk bot commented Dec 19, 2022

Going to push as commit bac8ee8.
Since your change was applied there have been 7 commits pushed to the master branch:

  • ae86ed3: 8297067: Update Gradle to 7.6
  • 30147d2: 8298496: IconifyTest fails intermittently on Linux
  • 58376eb: 8187145: (Tree)TableView with null selectionModel: throws NPE on sorting
  • adfc022: 8290040: Provide simplified deterministic way to manage listeners
  • f217d5e: 8298200: Clean up raw type warnings in javafx.beans.property.* and com.sun.javafx.property.*
  • 8763e8b: 8190411: NPE in SliderSkin:140 if Slider.Tooltip.autohide is true
  • dadfcaf: 8295339: DatePicker updates its value property with wrong date when dialog closes

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Dec 19, 2022
@openjdk openjdk bot closed this Dec 19, 2022
@openjdk openjdk bot removed ready Ready to be integrated rfr Ready for review sponsor Ready to sponsor labels Dec 19, 2022
@openjdk
Copy link

openjdk bot commented Dec 19, 2022

@arapte @DeanWookey Pushed as commit bac8ee8.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

4 participants