DataBinder uses a default limit of 256 for array/collection auto-growing (SPR-7842)
This commit is contained in:
@@ -34,6 +34,7 @@ import org.springframework.beans.BeanWithObjectProperty;
|
||||
import org.springframework.beans.DerivedTestBean;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.beans.IndexedTestBean;
|
||||
import org.springframework.beans.InvalidPropertyException;
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.beans.NotWritablePropertyException;
|
||||
import org.springframework.beans.NullValueInNestedPathException;
|
||||
@@ -1487,7 +1488,6 @@ public class DataBinderTests extends TestCase {
|
||||
MutablePropertyValues mpvs = new MutablePropertyValues();
|
||||
mpvs.add("name", name);
|
||||
mpvs.add("beanName", beanName);
|
||||
|
||||
binder.bind(mpvs);
|
||||
|
||||
assertEquals(name, testBean.getName());
|
||||
@@ -1496,6 +1496,62 @@ public class DataBinderTests extends TestCase {
|
||||
assertEquals("beanName", disallowedFields[0]);
|
||||
}
|
||||
|
||||
public void testAutoGrowWithinDefaultLimit() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
DataBinder binder = new DataBinder(testBean, "testBean");
|
||||
|
||||
MutablePropertyValues mpvs = new MutablePropertyValues();
|
||||
mpvs.add("stringArray[4]", "");
|
||||
binder.bind(mpvs);
|
||||
|
||||
assertEquals(5, testBean.getStringArray().length);
|
||||
}
|
||||
|
||||
public void testAutoGrowBeyondDefaultLimit() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
DataBinder binder = new DataBinder(testBean, "testBean");
|
||||
|
||||
MutablePropertyValues mpvs = new MutablePropertyValues();
|
||||
mpvs.add("stringArray[256]", "");
|
||||
try {
|
||||
binder.bind(mpvs);
|
||||
fail("Should have thrown InvalidPropertyException");
|
||||
}
|
||||
catch (InvalidPropertyException ex) {
|
||||
// expected
|
||||
assertTrue(ex.getRootCause() instanceof IndexOutOfBoundsException);
|
||||
}
|
||||
}
|
||||
|
||||
public void testAutoGrowWithinCustomLimit() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
DataBinder binder = new DataBinder(testBean, "testBean");
|
||||
binder.setAutoGrowCollectionLimit(10);
|
||||
|
||||
MutablePropertyValues mpvs = new MutablePropertyValues();
|
||||
mpvs.add("stringArray[4]", "");
|
||||
binder.bind(mpvs);
|
||||
|
||||
assertEquals(5, testBean.getStringArray().length);
|
||||
}
|
||||
|
||||
public void testAutoGrowBeyondCustomLimit() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
DataBinder binder = new DataBinder(testBean, "testBean");
|
||||
binder.setAutoGrowCollectionLimit(10);
|
||||
|
||||
MutablePropertyValues mpvs = new MutablePropertyValues();
|
||||
mpvs.add("stringArray[16]", "");
|
||||
try {
|
||||
binder.bind(mpvs);
|
||||
fail("Should have thrown InvalidPropertyException");
|
||||
}
|
||||
catch (InvalidPropertyException ex) {
|
||||
// expected
|
||||
assertTrue(ex.getRootCause() instanceof IndexOutOfBoundsException);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class BeanWithIntegerList {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user