RFR: 8187145: (Tree)TableView with null selectionModel: throws NPE on sorting [v5]

Ajit Ghaisas aghaisas at openjdk.org
Fri Nov 4 05:09:57 UTC 2022


On Thu, 3 Nov 2022 16:23:51 GMT, Andy Goryachev <angorya at openjdk.org> wrote:

>> What I mean by code simplification is -
>> 
>>         boolean isAlreadySelected = false;
>>         MultipleSelectionModel<?> sm = getSelectionModel();
>>         if (sm != null) {
>>             isAlreadySelected = sm.isSelected(index);
>> 
>>             if (isAlreadySelected && shortcutDown) {
>>                 sm.clearSelection(index);
>>                 getFocusModel().focus(index);
>>                 isAlreadySelected = false;
>>             } else {
>>                 sm.clearAndSelect(index);
>>             }
>>         }
>
> in this version, there are code paths where you assign the same variable twice.  I don't do that, I don't like doing that.  Is this required or in the code style?

It may not be the code style requirement, but generally, it is a good practice to initialize the variable explicitly at the time of declaration. My version saves an `else` block as well.
Anyway, I will not insist on this as it is a trivial code style preference.

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

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


More information about the openjfx-dev mailing list