Skip to content
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

DataBinder throws StringIndexOutOfBoundsException for indexed property without nested property path #34121

Closed
ecolinet-orange opened this issue Dec 19, 2024 · 3 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Milestone

Comments

@ecolinet-orange
Copy link

ecolinet-orange commented Dec 19, 2024

Trying to migrate from Spring Famework 6.1 to 6.2, I get an exception in Spring's validation code, located in the DataBinder::getIndexes method.

When I look at the code it looks like a bug.

@Nullable
private static SortedSet<Integer> getIndexes(String paramPath, ValueResolver valueResolver) {
	SortedSet<Integer> indexes = null;
	for (String name : valueResolver.getNames()) {
		if (name.startsWith(paramPath + "[")) {
			int endIndex = name.indexOf(']', paramPath.length() + 2);		// returns -1
			String rawIndex = name.substring(paramPath.length() + 1, endIndex); 	// throws java.lang.StringIndexOutOfBoundsException
			int index = Integer.parseInt(rawIndex);
			indexes = (indexes != null ? indexes : new TreeSet<>());
			indexes.add(index);
		}
	}
	return indexes;
}

In my case, name contains someField[], so paramPath.length() + 2 points outside the string. I think that paramPath.length() + 1 should be used instead.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 19, 2024
@jhoeller jhoeller added type: regression A bug that is also a regression in: core Issues in core modules (aop, beans, core, context, expression) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Dec 19, 2024
@jhoeller jhoeller added this to the 6.2.2 milestone Dec 19, 2024
@sbrannen
Copy link
Member

This is closely related to:

And the two should be looked at in conjunction.

@sbrannen sbrannen changed the title DataBinder throws java.lang.StringIndexOutOfBoundsException DataBinder throws StringIndexOutOfBoundsException for indexed property without nested property path Dec 19, 2024
@simonbasle
Copy link
Contributor

@ecolinet-orange can you provide a more detailed example of something that was working in 6.1.x? Even though I'm able to reproduce the exception when posting an array or list, the case I have simply leads to a null value for the bound param on 6.1.x...

@simonbasle simonbasle added the status: waiting-for-feedback We need additional information before we can continue label Dec 26, 2024
@simonbasle simonbasle self-assigned this Dec 26, 2024
@simonbasle
Copy link
Contributor

@ecolinet-orange I have attempted a fix, but please still ping me in a comment to provide the requested details, and I'll reopen this issue if needed. Feel free to also test out snapshots and report if your issue is indeed fixed.

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) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

5 participants