List constructor arg initialized correctly

DataBinder now uses the calculated List size rather than
the number of indexes to initialize the list.

Closes gh-34145
This commit is contained in:
rstoyanchev
2024-12-30 10:46:40 +00:00
parent 59ed4686c5
commit 4350fc21b3
2 changed files with 21 additions and 1 deletions

View File

@@ -1060,7 +1060,9 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
}
int size = (indexes.last() < this.autoGrowCollectionLimit ? indexes.last() + 1 : 0);
List<V> list = (List<V>) CollectionFactory.createCollection(paramType, size);
indexes.forEach(i -> list.add(null));
for (int i = 0; i < size; i++) {
list.add(null);
}
for (int index : indexes) {
list.set(index, (V) createObject(elementType, paramPath + "[" + index + "].", valueResolver));
}