diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java b/org.springframework.beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java index 438403d2074..46424861a78 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java @@ -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, diff --git a/org.springframework.context/src/test/java/org/springframework/format/number/NumberFormattingTests.java b/org.springframework.context/src/test/java/org/springframework/format/number/NumberFormattingTests.java index 26c86fd149e..510dbbfea48 100644 --- a/org.springframework.context/src/test/java/org/springframework/format/number/NumberFormattingTests.java +++ b/org.springframework.context/src/test/java/org/springframework/format/number/NumberFormattingTests.java @@ -24,7 +24,6 @@ import java.util.Locale; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.springframework.beans.MutablePropertyValues; import org.springframework.context.i18n.LocaleContextHolder; diff --git a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/Spr7839Tests.java b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/Spr7839Tests.java index b61759a9a11..00cfa2c772e 100644 --- a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/Spr7839Tests.java +++ b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/Spr7839Tests.java @@ -94,14 +94,13 @@ public class Spr7839Tests { @Test @Ignore public void arrayOfLists() throws Exception { - // TODO two issues here: no autogrow for array properties, and GenericCollectionResolver not capable of accessing nested element type + // TODO TypeDescriptor not capable of accessing nested element type for arrays request.setRequestURI("/nested/arrayOfLists"); request.addParameter("nested.arrayOfLists[0]", "Nested1,Nested2"); adapter.handle(request, response, controller); } @Test - @Ignore public void map() throws Exception { request.setRequestURI("/nested/map"); request.addParameter("nested.map['apple'].foo", "bar"); @@ -145,7 +144,6 @@ public class Spr7839Tests { @RequestMapping("/nested/arrayOfLists") public void handlerArrayOfLists(JavaBean bean) { - System.out.println(bean.nested.arrayOfLists[0].get(1).getClass()); assertEquals("Nested2", bean.nested.arrayOfLists[0].get(1).foo); }