array autogrow on set e.g. array[0]=foo

This commit is contained in:
Keith Donald
2011-01-07 17:28:18 +00:00
parent 2ef629d5a8
commit 5d6840e877
3 changed files with 8 additions and 6 deletions

View File

@@ -37,7 +37,6 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.CollectionFactory;
import org.springframework.core.GenericCollectionTypeResolver;
import org.springframework.core.MethodParameter;
@@ -946,12 +945,18 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra
int arrayIndex = Integer.parseInt(key);
Object oldValue = null;
try {
if (isExtractOldValueForEditor()) {
if (isExtractOldValueForEditor() && arrayIndex < Array.getLength(propValue)) {
oldValue = Array.get(propValue, arrayIndex);
}
Object convertedValue = convertIfNecessary(propertyName, oldValue, pv.getValue(), requiredType,
PropertyTypeDescriptor.forNestedType(requiredType, new MethodParameter(pd.getReadMethod(), -1, tokens.keys.length), pd));
// TODO reduce this grow algorithm along side the null gap algorithm for setting lists below ... the two are inconsistent
propValue = growArrayIfNecessary(propValue, arrayIndex, actualName);
Array.set(propValue, arrayIndex, convertedValue);
PropertyValue newValue = new PropertyValue(actualName, propValue);
newValue.resolvedDescriptor = pd;
newValue.conversionNecessary = false;
setPropertyValue(newValue);
}
catch (IndexOutOfBoundsException ex) {
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,