-
Notifications
You must be signed in to change notification settings - Fork 505
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
8290765: Remove parent disabled/treeVisible listeners #841
Conversation
👋 Welcome back mstrauss! A progress list of the required criteria for merging this PR into |
@mstr2 this pull request can not be integrated into git checkout fixes/node-listener-cleanup
git fetch https://git.openjdk.org/jfx master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push |
/reviewers 2 |
@kevinrushforth |
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.
Tested with some layout and controls. LGTM.
if (Node.this instanceof Parent) { | ||
List<Node> children = ((Parent)Node.this).getChildren(); | ||
if (children != null) { | ||
for (Node child : children) { | ||
child.updateDisabled(); | ||
} | ||
} | ||
} |
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.
Because we can use Java 17 now, you can use pattern matching for instanceof
. Also, from what I see, getChildren()
can never return null
. So, we can write
if (Node.this instanceof Parent parent) {
parent.getChildren().forEach(child -> child.updateDisabled());
}
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.
Since getChildren()
is not final, one can easily override it and return null.
Therefore, this check should still be done here.
Maybe we even need to check that every child is not null, since again I can override getChildren()
and return a list that allows null. (The default implementation in Parent
throws an exception when adding a null child)
Interestingly, the javadoc of getChildren()
states that one should call the super method when overriding (although this can't be enforced). So this is probably a hypothetical case.
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.
It's definitely a hypothetical case. getChildren()
is called all over the place in JavaFX without a null check, so I see no reason for null checks here.
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.
Technically correct, although the doc of getChildren()
specifically says:
Note to subclasses: if you override this method, you must return from your implementation the result of calling this super method. The actual list instance returned from any getChildren() implementation must be the list owned and managed by this Parent. The only typical purpose for overriding this method is to promote the method to be public.
So considering the case that an overriding method will return null
is not practical.
As for a null
child, I think that that's also not allowed. Considering that a child can be added at most once to a scenegraph, it would mean that only 1 null
child is allowed. There might be more issues with null
children. I don't think there's a good reason to check for them.
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.
Yep, right. While it is possible to override getChildren()
and return null, it will break everywhere so we can also omit the null check here.
It's true that However, in this specific instance, The same problem exists for But there's a serious problem with the null checking approach: it's calling a protected method at an unexpected time, before the constructor of a derived class has run. Since that's not what derived classes would expect, I have instead opted for a different solution, which includes a |
I haven't looked at the code yet, but in general it's not considered a good idea to expose an object before it's instantiated. Not sure if we have a choice here though. |
I agree, that's why the |
# Conflicts: # modules/javafx.graphics/src/main/java/javafx/scene/Node.java
I've resolved some merge conflicts with the latest |
Can this not be done in a way that doesn't require this Result of this code for an uninitialized
Then
End result of running all that code... |
That's a good idea, and a also a good observation that the constructor only really sets |
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.
Looks good. I ran the tests and they pass. Left a few optional comments.
Maybe @kevinrushforth will want to have a look too before you merge.
//if (PerformanceTracker.isLoggingEnabled()) { | ||
// PerformanceTracker.logEvent("Node.init for [{this}, id=\"{id}\"]"); | ||
//} | ||
updateTreeVisible(false); | ||
//if (PerformanceTracker.isLoggingEnabled()) { | ||
// PerformanceTracker.logEvent("Node.postinit " + | ||
// "for [{this}, id=\"{id}\"] finished"); | ||
//} |
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.
Not sure if these comments are intended to be used for something. I doubt it though.
@mstr2 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 12 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 |
I took a quick look and it seems fine to me. I recommend to wait for a day or two to see if @arapte has any additional comments on the changes (since his review is stale). |
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 missed that you can also change the foreach loop on the treeVisible method too, but it's not important.
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.
Looks good to me too.
/integrate |
Going to push as commit 44b8c62.
Your commit was automatically rebased without conflicts. |
Node
adds InvalidationListeners to its parent'sdisabled
andtreeVisible
properties and calls its ownupdateDisabled()
andupdateTreeVisible(boolean)
methods when the property values change.These listeners are not required, since
Node
can easily call theupdateDisabled()
andupdateTreeVisible(boolean)
methods on its children, saving the memory cost of maintaining listeners and bindings.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx pull/841/head:pull/841
$ git checkout pull/841
Update a local copy of the PR:
$ git checkout pull/841
$ git pull https://git.openjdk.org/jfx pull/841/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 841
View PR using the GUI difftool:
$ git pr show -t 841
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/841.diff