RFR: 8360070: AccessibleText.getBeforeIndex returns null for last character
Abhishek Kumar
abhiscxk at openjdk.org
Tue Jun 24 11:47:27 UTC 2025
On Mon, 23 Jun 2025 23:24:14 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:
>> `AccessibleText.getBeforeIndex` method returns `null for last characte`r due to the **wrong boundary value condition check**.
>> This method returns `null` when the `passed index parameter` is equal to `text's length` which is incorrect.
>> `getBeforeIndex` method should return `null` only if the **passed index parameter is less than 0 and greater than the text's length**.
>>
>> After modifying the condition check, expected character is returned. Test is added to verify the check,
>
>>getBeforeIndex method should return null only if the passed index parameter is less than 0 and greater than the text's length.
>
> I am not sure about the statement above. I think the check should take care of the direction, which is -1 in your case. This is actually properly handled by the code below(in t he same method you changed):
>
> if (index + direction < model.getLength() &&
> index + direction >= 0) {
> return model.getText(index + direction, 1);
> }
>
> The code you added also affects WORD and SENTENCE cases. I suggest covering those with a test as well.
> @mrserb The code you added also affects WORD and SENTENCE cases. I suggest covering those with a test as well.
Yes, that affects the WORD and SENTENCE cases. I have extended the test to cover them.
Before the fix the returned value for WORD and SENTENCE is null that seems incorrect as well.
I think the return string in case of WORD should be `Test6` and SENTENCE should be `Test4 Test5. `
-------------
PR Comment: https://git.openjdk.org/jdk/pull/25941#issuecomment-3000004752
More information about the client-libs-dev
mailing list