-
Notifications
You must be signed in to change notification settings - Fork 471
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
8339603: Seal the class hierarchy of Node, Camera, LightBase, Shape, Shape3D #1556
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back mstrauss! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
Webrevs
|
What is the benefit of this change? Also, this change is breaking. One can currently create a Node:
|
It enforces a system invariant at compile-time instead of run-time.
You can't do anything meaningful with this node. As soon as you add it to a scene graph, you'll get a runtime exception. The fact that you can't extend |
If this PR goes forward, it will need a CSR, since it does impact source code compatibility. As you point out, you can't usefully extend Node today, since you will get a runtime exception as soon as you try to create an instance of a subclassed Node, so what this does is move a runtime error to compile time. That's generally a good thing, but..is it worth doing? We can continue to discuss. /csr |
@kevinrushforth has indicated that a compatibility and specification (CSR) request is needed for this pull request. @mstr2 please create a CSR request for issue JDK-8339603 with the correct fix version. This pull request cannot be integrated until the CSR request is approved. |
In addition to moving a runtime error to compile time, it also documents intent for future JavaFX maintainers. Given that the change is not invasive and has pretty much no downsides, I think it is worth it. |
But I can, and the code provided above runs with no exception - in either Whether such code is meaningful is another story. I would vote against this change. |
But you just proved that you can violate a system invariant. The existing code tries to detect some violations and alerts you that extending Node is not supported by JavaFX. |
can you point me to where it says one can't extend Node or that it is verboten? |
I thought about doing this some years ago for
However, I didn't see enough value in this. There is some small benefit for The downside is minor too: custom shaders will allow user implementations, but that's not coming any time soon. Since removing As for |
|
The documentation for
Just above StringID. |
a comment in some internal helper class is not, in my opinion, a normative reference. I am not against this change in principle - it might be a welcome enhancement, if it were solving a real world problem. I am against this change because it has a risk of existing application failing (compatibility risk). App developers are a creative bunch, they often do things that the platform developers did not expect. |
"should" and "may" are not the same as "must" and "will". but anyway, my objection is due to possible compatibility risk. edit: +1 for rtfm :-) |
I forgot to mention |
I wonder if it is possible to have some kind of interim solution that will warn the app developers that they are doing something they are not supposed to?
What do you think? |
I think this is just suboptimal language, and not a material distinction. You will get a runtime error if you use it in any meaningful way. Anyway, if a developer really wants to create an instance of |
Indeed it is a case of suboptimal language. The intention was to make it clear that this is not supported. Period. And it isn't in any meaningful way. If there are corner cases where we miss throwing an exception, that is a bug. There might be other reasons to not make this change -- I haven't formed an opinion yet -- but concern over compatibility isn't one of them. |
public abstract class Node implements EventTarget, Styleable { | ||
public abstract sealed class Node | ||
implements EventTarget, Styleable | ||
permits AbstractNode, Camera, LightBase, Parent, SubScene, Canvas, ImageView, Shape, Shape3D { |
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.
We may need to use stronger wording in javadoc in regards to extending Nodes. should -> must, etc. (or, rather, 'cannot' and possibly explain why?)
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've removed the language that you can't extend those classes, as it is now redundant because it is enforced by the compiler. We shouldn't document obvious facts without providing any added value (for example, adding context and reasoning why it's the way it is).
@mstr2 This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
@mstr2 I think there is value in proceeding with this. Can you merge the latest master into your branch? (That will also keep the Skara bot from auto-closing it). |
@@ -57,7 +57,7 @@ public static void initHelper(Camera camera) { | |||
|
|||
@Override | |||
protected NGNode createPeerImpl(Node node) { | |||
throw new UnsupportedOperationException("Applications should not extend the Camera class directly."); | |||
throw new AssertionError(); |
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.
is this the right error type?
why change UnsupportedOperationException?
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.
When Camera
is sealed, this method cannot be called by user code. UnsupportedOperationException
would be okay if it could reasonably be called, but this is now an invariant that would signal a bug in JavaFX.
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.
maybe an explanatory comment should be added?
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.
We typically use InternalError
for the case where there should be no possible reason for a particular case, but also use AssertionError
in some cases. Either is OK with me. I agree that a comment to the affect of "Should not ever get here" wouldn't be a bad idea.
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've added a comment to CameraHelper
and LightBaseHelper
.
If this goes forward, please seal |
If we seal |
I don't see why they are related, but if |
They are in the same package, and they are related insofar as an argument for sealing |
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.
thank you for adding the comment!
@mstr2 This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
None of these classes can be extended by user code, and any attempt to do so will fail at runtime with an exception. For this reason, we can seal the class hierarchy and remove the run-time checks to turn this into a compile-time error instead.
In some cases,
Node
andShape
are extended by JavaFX classes in other modules, preventing those derived classes from being permitted subclasses. A non-exportedAbstractNode
andAbstractShape
class is provided just for these scenarios. Note that introducing a new superclass is a source- and binary-compatible change (see JLS ch. 13).I'm not sure if this change requires a CSR, as it doesn't change the specification in any meaningful way. There can be no valid JavaFX program that is affected by this change.
/reviewers 2
Progress
Issues
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1556/head:pull/1556
$ git checkout pull/1556
Update a local copy of the PR:
$ git checkout pull/1556
$ git pull https://git.openjdk.org/jfx.git pull/1556/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 1556
View PR using the GUI difftool:
$ git pr show -t 1556
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1556.diff
Using Webrev
Link to Webrev Comment