On Tue, 24 Jun 2025 11:44:13 GMT, Abhishek Kumar <abhis...@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, > > Abhishek Kumar has updated the pull request incrementally with one additional > commit since the last revision: > > Test extended for WORD and SENTENCE I modified Abhishek's test: System.out.println(" i bef at aft"); for (int i : new int[] {0, 1, 2, 8, 9, 10}) { System.out.printf("%2d%5s%5s%5s\n", i, at.getBeforeIndex(CHARACTER, i), at.getAtIndex(CHARACTER, i), at.getAfterIndex(CHARACTER, i)); } This way, I created a table of returned values: Text: "0123456789" Text Length: 10 i bef at aft 0 null 0 1 1 0 1 2 2 1 2 3 8 7 8 9 9 8 9 null 10 null null null I'd expect to see 9 as the return value of `getBeforeIndex` for the index of 10. This would make the table symmetrical. Therefore, I'm in favour for Abhishek's proposed fix. --- The description of the methods in `AccessibleText` is vague. None of the three methods specifies what the index means and what values are accepted for it. According to the text model, index 10 is still valid, it's the index between the last character and the implied line break, so `tf.getDocument().getText(10, 1)` returns `\n`. Having this in mind, the specification of the `getBeforeIndex`, `getAtIndex`, `getAfterIndex` methods should be updated to *explicitly specify the valid values for the `index` parameter*. ------------- PR Comment: https://git.openjdk.org/jdk/pull/25941#issuecomment-3067274720