RFR: 8279640: ListView with null SelectionModel/FocusModel throws NPE

Marius Hanl mhanl at openjdk.java.net
Tue Jan 11 13:07:38 UTC 2022


On Tue, 11 Jan 2022 09:01:51 GMT, John Hendrikx <jhendrikx at openjdk.org> wrote:

> ```
> public final MultipleSelectionModel<T> getSelectionModel() {
>     return selectionModel == null ? null : 
>          selectionModel.get() == NONE_SELECTION_MODEL ? null : selectionModel.get();
> }
> ```

That would work altough I think it's a bit hacky as when I listen on the `selectionModelProperty` I still would get the noop selection model.
I'm in general not a fan of 'self-changing' properties. When a null value is possible, guards against are needed. 
Unfortunately there is no built-in way to forbid null in Java as whole.

> A check can also be done to see if something matches the `NONE` model, just like you can check for `null`, so you can still fast return in special cases.

But then I don't see any advantage as it makes no difference if we check for NONE model or null. Checks are needed in any case.

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

PR: https://git.openjdk.java.net/jfx/pull/711


More information about the openjfx-dev mailing list