Skip to content

fix: prevent IndexOutOfBoundsException for single-character getter names - #590

Open
adityaanikam wants to merge 1 commit into
victools:mainfrom
adityaanikam:fix-single-char-property-name-589
Open

fix: prevent IndexOutOfBoundsException for single-character getter names#590
adityaanikam wants to merge 1 commit into
victools:mainfrom
adityaanikam:fix-single-char-property-name-589

Conversation

@adityaanikam

Copy link
Copy Markdown

Fixes #589.

MethodScope.deriveFieldName() strips the get/is prefix 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 like getX() (property name X after stripping the prefix) throws StringIndexOutOfBoundsException instead of returning x.

Added a methodNameWithoutPrefix.length() > 1 check alongside the existing uppercase check. With the guard, single-character names fall through to the existing decapitalization line, which correctly returns "x" for "X" — matching Introspector.decapitalize("X").

Added getX()/getX, x test cases to MethodScopeTest#testGetSchemaPropertyName, alongside the existing getxIndex/isURL cases that already cover the two-character JavaBeans convention this method implements.

@sonarqubecloud

Copy link
Copy Markdown

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Bug in MethodScope.deriveFieldName: java.lang.StringIndexOutOfBoundsException when method field name is just 1 character long

1 participant