[java] Keys: enforce CharSequence contract in charAt()#17166
Merged
asolntsev merged 5 commits intoSeleniumHQ:trunkfrom Mar 4, 2026
Merged
[java] Keys: enforce CharSequence contract in charAt()#17166asolntsev merged 5 commits intoSeleniumHQ:trunkfrom
asolntsev merged 5 commits intoSeleniumHQ:trunkfrom
Conversation
Contributor
Review Summary by QodoEnforce CharSequence contract in Keys.charAt() bounds checking
WalkthroughsDescription• Enforce bounds checking in Keys.charAt() method • Throw IndexOutOfBoundsException for invalid indexes • Comply with CharSequence contract requirements • Prevent silent violations and incorrect comparisons File Changes1. java/src/org/openqa/selenium/Keys.java
|
Contributor
Code Review by Qodo
1.
|
4f2a4d1 to
2754996
Compare
Member
|
@seethinajayadileep I just approved the workflows to run for this PR, but we are having some issues so you will likely see some unrelated test failures in CI. |
asolntsev
approved these changes
Mar 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💥 What does this PR do?
Updates
Keys.charAt(int index)to validate the index and throwIndexOutOfBoundsExceptionwhen the index is not0.Previously, the method returned the null character (
'\u0000') for anyindex other than
0, which silently violated theCharSequencecontract.This change ensures:
length()returns1charAt(0)returns the key codecharAt(index != 0)throwsIndexOutOfBoundsExceptionThis aligns the implementation with expected
CharSequencebehavior.🔧 Implementation Notes
Keysrepresents a single Unicode PUA character. Since its length isalways
1, only index0is valid.Instead of returning
'\u0000'for invalid indexes (which can mask bugsand produce incorrect comparisons), the method now explicitly throws
IndexOutOfBoundsException.Alternative considered:
'\u0000') — rejected becauseit silently hides incorrect usage and breaks contract expectations.
💡 Additional Considerations
charAt(0)).toString(),subSequence(), orchord()behavior.🔄 Types of changes