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

Open
ecolinet-orange opened this issue Dec 19, 2024 · 1 comment
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
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

4 participants