Skip to content

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

Closed
@ecolinet-orange

Description

@ecolinet-orange

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.

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions