On Sun, 13 Jul 2025 20:06:10 GMT, Alexey Ivanov <aiva...@openjdk.org> wrote:
>I'd expect to see 9 as the return value of getBeforeIndex for the index of 10. >This would make the table symmetrical. Why do you expect that? The spec states that the index should be "an index within the text." That index is also used in other methods, such as getCharacterBounds(), etc. If we fixed it only for text at the end, it would make the behavior even less symmetric, since for a negative value, the model will always throw an exception. >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. The last character is implementation detail, it is not part of the "users data" this is the reason why it is excluded from the Document.getLength(). So passing length as a last character might cause an exception for custom documents. We also have the getCharCount() methods which returns "the number of characters (valid indices)". Also, why are we only talking about JTextComponent? There are other same implementations of AccessibleText for example [JLabel](https://github.com/openjdk/jdk/blob/0acd065bf5a75090b84c28b28856a62d86c52791/src/java.desktop/share/classes/javax/swing/JLabel.java#L1287). >Here i disagree, the "within the text" does not imply that the position behind >the last character is not within the text. Otherwise with the caret is at the >end of the text it is impossible to request last word or character before the >caret position which is one of the valid use cases of this accessibility >method. I think the fix is valid. It means exactly that, and it is also impossible to request the first character after the caret position if it is at the start of the document. For both cases getAtIndex() should work. ------------- PR Comment: https://git.openjdk.org/jdk/pull/25941#issuecomment-3071806404