properly wrap IndexOutOfBoundsException even for List

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4655 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Juergen Hoeller 2011-07-03 20:24:12 +00:00
parent 9be513d225
commit 17a56fcfdd
2 changed files with 13 additions and 7 deletions

View File

@ -1005,7 +1005,13 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra
list.add(convertedValue); list.add(convertedValue);
} }
else { 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) { else if (propValue instanceof Map) {

View File

@ -1501,10 +1501,10 @@ public class DataBinderTests extends TestCase {
DataBinder binder = new DataBinder(testBean, "testBean"); DataBinder binder = new DataBinder(testBean, "testBean");
MutablePropertyValues mpvs = new MutablePropertyValues(); MutablePropertyValues mpvs = new MutablePropertyValues();
mpvs.add("stringArray[4]", ""); mpvs.add("friends[4]", "");
binder.bind(mpvs); binder.bind(mpvs);
assertEquals(5, testBean.getStringArray().length); assertEquals(5, testBean.getFriends().size());
} }
public void testAutoGrowBeyondDefaultLimit() throws Exception { public void testAutoGrowBeyondDefaultLimit() throws Exception {
@ -1512,7 +1512,7 @@ public class DataBinderTests extends TestCase {
DataBinder binder = new DataBinder(testBean, "testBean"); DataBinder binder = new DataBinder(testBean, "testBean");
MutablePropertyValues mpvs = new MutablePropertyValues(); MutablePropertyValues mpvs = new MutablePropertyValues();
mpvs.add("stringArray[256]", ""); mpvs.add("friends[256]", "");
try { try {
binder.bind(mpvs); binder.bind(mpvs);
fail("Should have thrown InvalidPropertyException"); fail("Should have thrown InvalidPropertyException");
@ -1529,10 +1529,10 @@ public class DataBinderTests extends TestCase {
binder.setAutoGrowCollectionLimit(10); binder.setAutoGrowCollectionLimit(10);
MutablePropertyValues mpvs = new MutablePropertyValues(); MutablePropertyValues mpvs = new MutablePropertyValues();
mpvs.add("stringArray[4]", ""); mpvs.add("friends[4]", "");
binder.bind(mpvs); binder.bind(mpvs);
assertEquals(5, testBean.getStringArray().length); assertEquals(5, testBean.getFriends().size());
} }
public void testAutoGrowBeyondCustomLimit() throws Exception { public void testAutoGrowBeyondCustomLimit() throws Exception {
@ -1541,7 +1541,7 @@ public class DataBinderTests extends TestCase {
binder.setAutoGrowCollectionLimit(10); binder.setAutoGrowCollectionLimit(10);
MutablePropertyValues mpvs = new MutablePropertyValues(); MutablePropertyValues mpvs = new MutablePropertyValues();
mpvs.add("stringArray[16]", ""); mpvs.add("friends[16]", "");
try { try {
binder.bind(mpvs); binder.bind(mpvs);
fail("Should have thrown InvalidPropertyException"); fail("Should have thrown InvalidPropertyException");