RFR: 8290765: Remove parent disabled/treeVisible listeners

Kevin Rushforth kcr at openjdk.org
Thu Aug 25 13:49:37 UTC 2022


On Thu, 25 Aug 2022 13:36:01 GMT, Marius Hanl <mhanl at openjdk.org> wrote:

>> modules/javafx.graphics/src/main/java/javafx/scene/Node.java line 1919:
>> 
>>> 1917:                             }
>>> 1918:                         }
>>> 1919:                     }
>> 
>> 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());
>> }
>
> 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.

-------------

PR: https://git.openjdk.org/jfx/pull/841


More information about the openjfx-dev mailing list