提交 22939b6d 编写于 作者: J Juergen Hoeller

properly wrap IndexOutOfBoundsException even for List

上级 b8f7d324
......@@ -1005,7 +1005,13 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra
list.add(convertedValue);
}
else {
list.set(index, convertedValue);
try {
list.set(index, convertedValue);
}
catch (IndexOutOfBoundsException ex) {
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
"Invalid list index in property path '" + propertyName + "'", ex);
}
}
}
else if (propValue instanceof Map) {
......
......@@ -1501,10 +1501,10 @@ public class DataBinderTests extends TestCase {
DataBinder binder = new DataBinder(testBean, "testBean");
MutablePropertyValues mpvs = new MutablePropertyValues();
mpvs.add("stringArray[4]", "");
mpvs.add("friends[4]", "");
binder.bind(mpvs);
assertEquals(5, testBean.getStringArray().length);
assertEquals(5, testBean.getFriends().size());
}
public void testAutoGrowBeyondDefaultLimit() throws Exception {
......@@ -1512,7 +1512,7 @@ public class DataBinderTests extends TestCase {
DataBinder binder = new DataBinder(testBean, "testBean");
MutablePropertyValues mpvs = new MutablePropertyValues();
mpvs.add("stringArray[256]", "");
mpvs.add("friends[256]", "");
try {
binder.bind(mpvs);
fail("Should have thrown InvalidPropertyException");
......@@ -1529,10 +1529,10 @@ public class DataBinderTests extends TestCase {
binder.setAutoGrowCollectionLimit(10);
MutablePropertyValues mpvs = new MutablePropertyValues();
mpvs.add("stringArray[4]", "");
mpvs.add("friends[4]", "");
binder.bind(mpvs);
assertEquals(5, testBean.getStringArray().length);
assertEquals(5, testBean.getFriends().size());
}
public void testAutoGrowBeyondCustomLimit() throws Exception {
......@@ -1541,7 +1541,7 @@ public class DataBinderTests extends TestCase {
binder.setAutoGrowCollectionLimit(10);
MutablePropertyValues mpvs = new MutablePropertyValues();
mpvs.add("stringArray[16]", "");
mpvs.add("friends[16]", "");
try {
binder.bind(mpvs);
fail("Should have thrown InvalidPropertyException");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册