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.
Comment From: sbrannen
This is closely related to:
-
34043
And the two should be looked at in conjunction.
Comment From: simonbasle
@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...
Comment From: simonbasle
@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.