-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8360070: AccessibleText.getBeforeIndex returns null for last character #25941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back abhiscxk! A progress list of the required criteria for merging this PR into |
@kumarabhi006 This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 38 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
@kumarabhi006 The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
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):
The code you added also affects WORD and SENTENCE cases. I suggest covering those with a test as well. |
I think the check is to ensure the passed index parameter is to verify the boundary of text length.
If the |
Yes, that affects the WORD and SENTENCE cases. I have extended the test to cover them. I think the return string in case of WORD should be |
throw new RuntimeException("The actual result does not match " + | ||
"the expected result."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not include the values in the error message?
throw new RuntimeException("The actual result does not match " + | |
"the expected result."); | |
throw new RuntimeException("Result doesn't match: '" + actual + "' vs. '" + expected + "'"); |
Yes, but the index passed to the method is
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 So, if someone wants to retrieve the first or last character, they shouldn't rely on Right ? |
What spec in particular? |
It says, |
That is my understanding. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
@aivanov-jdk @azuev-java As per the discussion with @mrserb here, 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 |
It might be useful |
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:
I'd expect to see 9 as the return value of Therefore, I'm in favour for Abhishek's proposed fix. The description of the methods in According to the text model, index 10 is still valid, it's the index between the last character and the implied line break, so Having this in mind, the specification of the |
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. |
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.
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.
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. |
I agree with @mrserb: there already is |
AccessibleText.getBeforeIndex
method returnsnull for last characte
r due to the wrong boundary value condition check.This method returns
null
when thepassed index parameter
is equal totext's length
which is incorrect.getBeforeIndex
method should returnnull
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,
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25941/head:pull/25941
$ git checkout pull/25941
Update a local copy of the PR:
$ git checkout pull/25941
$ git pull https://git.openjdk.org/jdk.git pull/25941/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 25941
View PR using the GUI difftool:
$ git pr show -t 25941
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25941.diff
Using Webrev
Link to Webrev Comment