RFR: 8290765: Remove parent disabled/treeVisible listeners
Nir Lisker
nlisker at openjdk.org
Thu Aug 25 13:52:52 UTC 2022
On Thu, 25 Aug 2022 13:46:26 GMT, Kevin Rushforth <kcr at openjdk.org> wrote:
>> 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.
>
> 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.
Technically correct, although the [doc of `getChildren()`](https://openjfx.io/javadoc/18/javafx.graphics/javafx/scene/Parent.html#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.
-------------
PR: https://git.openjdk.org/jfx/pull/841
More information about the openjfx-dev
mailing list