RFR: 8176270: Adding ChangeListener to TextField.selectedTextProperty causes StringOutOfBoundsException [v6]

Robert Lichtenberger rlichten at openjdk.java.net
Thu Jul 2 05:29:16 UTC 2020


On Tue, 30 Jun 2020 23:05:40 GMT, Kevin Rushforth <kcr at openjdk.org> wrote:

>> Robert Lichtenberger has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   8176270: Adding ChangeListener to TextField.selectedTextProperty causes StringOutOfBoundsException
>>   
>>   Move replaceSelectionAtEndWithListener test to general test class.
>>   Add a more general test for selection/text properties and replace/undo/redo operations.
>
> modules/javafx.controls/src/main/java/javafx/scene/control/TextInputControl.java line 186:
> 
>> 185:                 int length = txt.length();
>> 186:                 if (end > start + length) end = length;
>> 187:                 if (start > length-1) start = end = 0;
> 
> As I mentioned in [this comment in PR #73](https://github.com/openjdk/jfx/pull/73#discussion_r376528686), I think this
> test is wrong. The value of `start` has no impact on whether `end` is out of range. So... shouldn't this simply be `if
> (end > length) end = length;` ?

You're right. The whole point of the fix was to remove the need for any clamping by preventing the "in-between" updates
of the selected text property. I've checked that the condition in line 186 is never fulfilled now anymore and removed
it. I've also removed the clamping in the line below, because the only case where start > length-1 is now that start ==
length in which case also end == length and txt.substring(length, length) will be just as empty as txt.substring(0, 0).

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

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


More information about the openjfx-dev mailing list