fix: prevent IndexOutOfBoundsException for single-character getter names - #590
Open
adityaanikam wants to merge 1 commit into
Open
fix: prevent IndexOutOfBoundsException for single-character getter names#590adityaanikam wants to merge 1 commit into
adityaanikam wants to merge 1 commit into
Conversation
|
There was a problem hiding this comment.
Gates Passed
4 Quality Gates Passed
See analysis details in CodeScene
Absence of Expected Change Pattern
- jsonschema-generator/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/MethodScope.java is usually changed with: jsonschema-generator/jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/FieldScope.java
Quality Gate Profile: Clean Code Collective
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.
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.



Fixes #589.
MethodScope.deriveFieldName()strips theget/isprefix and only checks!name.isEmpty()before inspecting the second character to decide capitalization (methodNameWithoutPrefix.charAt(1)). That guarantees a length of at least 1, not 2, so a single-character property getter likegetX()(property nameXafter stripping the prefix) throwsStringIndexOutOfBoundsExceptioninstead of returningx.Added a
methodNameWithoutPrefix.length() > 1check alongside the existing uppercase check. With the guard, single-character names fall through to the existing decapitalization line, which correctly returns"x"for"X"— matchingIntrospector.decapitalize("X").Added
getX()/getX, xtest cases toMethodScopeTest#testGetSchemaPropertyName, alongside the existinggetxIndex/isURLcases that already cover the two-character JavaBeans convention this method implements.