RFR: 8279640: ListView with null SelectionModel/FocusModel throws NPE [v5]
Thiago Milczarek Sayao
tsayao at openjdk.org
Tue Sep 13 12:19:05 UTC 2022
On Mon, 12 Sep 2022 16:27:06 GMT, Marius Hanl <mhanl at openjdk.org> wrote:
>> This PR fixes a bunch of NPEs when a null `SelectionModel` or `FocusModel` is set on a `ListView`.
>>
>> The following NPEs are fixed (all are also covered by exactly one test case):
>> NPEs with null selection model:
>> - Mouse click on a `ListCell`
>> - SPACE key press
>> - KP_UP (arrow up) key press
>> - HOME key press
>> - END key press
>> - BACK_SLASH + CTRL key press
>>
>> NPEs with null focus model:
>> - SPACE key press
>> - Select an items: getSelectionModel().select(1)
>> - Clear-Select an item and add one after: `listView.getSelectionModel().clearAndSelect(1); listView.getItems().add("3");`
>
> Marius Hanl has updated the pull request incrementally with one additional commit since the last revision:
>
> Do selection/focus logic after the null check
>
> No need to prepare selection/focus stuff just to return later as one of them is null
Just updated to JavaFX 19 (without this fix) and noticed this NPE:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException: Cannot invoke "javafx.scene.control.TableView$TableViewSelectionModel.getSelectedCells()" because the return value of "javafx.scene.control.TableView.getSelectionModel()" is null
This is when setting SelectionModel to null (because I don't want the TableView to be selectable) and clicking on the headerbar to sort.
-------------
PR: https://git.openjdk.org/jfx/pull/711
More information about the openjfx-dev
mailing list