On Wed, 25 Jun 2025 15:05:27 GMT, Alexey Ivanov <[email protected]> wrote:
>>> > I think the check is to ensure the passed index parameter is to verify
>>> > the boundary of text length.
>>>
>>> Yes, but the index passed to the method is `an index within the text`, so
>>> it should be from 0 to length - 1. You can take a look at the opposite case
>>> when the index is outside the range, for example at the beginning of the
>>> text and getAfterIndex:
>>>
>>> > result = at.getAfterIndex(AccessibleText.CHARACTER, -1);
>>> > verifyResult("T", result);
>>>
>>> Is that expectation correct or not? I think we should first decide whether
>>> this is actually a bug or not.
>>
>> I got your point now. The spec says that `index an index within the text`
>> and that means the value should range from 0 to length - 1. And that means,
>> `getBeforeIndex` won't be able to fetch the last character and
>> `getAfterIndex` won't be able to fetch the first character.
>>
>> So, if someone wants to retrieve the first or last character, they shouldn't
>> rely on `getAfterIndex and getBeforeIndex` method respectively, rather use
>> `getAtIndex` method to get the first and last character with index passed as
>> 0 and length -1 respectively.
>>
>> Right ?
>
>> The spec says
>
> What spec in particular?
@aivanov-jdk @azuev-java As per the discussion with @mrserb
[here](https://github.com/openjdk/jdk/pull/25941#issuecomment-3003204161), it
seems this is not an issue with the code. I would like to know about your
opinion ?
If this is not an issue to fix, **can we update the javadoc for the APIs for
better understanding** ?
Something like `getBeforeIndex shouldn't be used to retrieve the last
character or word or sentence` and similar for getAfterIndex and getAtIndex
APIs.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/25941#issuecomment-3045669182