Skip to content

Ignore indexed parameter names without closing bracket in DataBinder - #37719

Open
Marti2203 wants to merge 2 commits into
spring-projects:mainfrom
Marti2203:databinder-unclosed-index
Open

Marti2203 wants to merge 2 commits into
spring-projects:mainfrom
Marti2203:databinder-unclosed-index

Conversation

@Marti2203

@Marti2203 Marti2203 commented Nov 18, 2026 •

Copy link
Copy Markdown

During constructor binding, DataBinder.getIndexes() and createMap() look for the closing bracket of a parameter name such as list[0] or map[key], and use the result of indexOf(']') without checking it. A request parameter whose name lacks the bracket, for example a[35 for a record or constructor-bound bean with an a parameter of List, array or Map type, therefore fails with:

java.lang.StringIndexOutOfBoundsException: Range [2, -1) out of bounds for length 4

and the request ends with a 500 error. This is the same code as gh-34121, which fixed the list[] form (no index) but not a name without the closing bracket.

This change skips such names, as is already done for other names that do not match the indexed form. Two new tests, DataBinderConstructTests.simpleListBindingIgnoresUnclosedIndex and simpleMapBindingIgnoresUnclosedKey, fail before the change and pass after it.

Testing: DataBinderConstructTests (30 tests), DataBinderTests (94) and DataBinderFieldAccessTests (9), :spring-context:checkstyleMain and checkstyleTest pass. 7.0.x and 6.2.x have the same code.

The issue was found by an LLM-assisted tool and verified manually.

During constructor binding, DataBinder.getIndexes() and createMap() look
for the closing bracket of a parameter name such as "list[0]" or
"map[key]" and use the result of indexOf(']') without checking it. A
request parameter whose name is missing the bracket, such as "list[35"
or "map[key", therefore fails with a StringIndexOutOfBoundsException, and
the request ends with a 500 error instead of the parameter being ignored.

Skip such names, as is already done for other names that do not match
the indexed form.

Signed-off-by: Martin Mirchev <mmirchev@comp.nus.edu.sg>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 18, 2026
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Nov 19, 2026
@sbrannen sbrannen self-assigned this Nov 19, 2026
@sbrannen sbrannen added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 19, 2026

@sbrannen sbrannen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @Marti2203,

Thanks for the PR. The change looks good.

However, a non-numeric or out-of-range index (for example, integerList[abc] or integerList[99999999999]) still causes an uncaught NumberFormatException in getIndexes(), which also results in a 500 error.

Since that's the same kind of problem in the same method, please ignore such names as well and add a test for that scenario.

Thanks

@sbrannen sbrannen added the status: waiting-for-feedback We need additional information before we can continue label Nov 19, 2026
@sbrannen sbrannen added this to the 7.1.1 milestone Nov 19, 2026
An index that Integer.parseInt() rejects, such as integerList[abc] or
integerList[99999999999], threw a NumberFormatException from getIndexes().
Skip such parameter names, as for an index without a closing bracket.

Signed-off-by: Martin Mirchev <mmirchev@comp.nus.edu.sg>
@Marti2203

Copy link
Copy Markdown
Author

Thanks. Done in 091e06e: an index that Integer.parseInt() rejects (integerList[abc], integerList[99999999999]) is now skipped like an unclosed one, and simpleListBindingIgnoresNonNumericOrOutOfRangeIndex covers it. It fails without the change with NumberFormatException: For input string: "99999999999".

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 19, 2026

This branch has not been deployed

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

Labels

in: core Issues in core modules (aop, beans, core, context, expression) status: feedback-provided Feedback has been provided type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants