BeanWrapper avoids StringIndexOutOfBoundsException for incompletely quoted keys

Issue: SPR-14293
master
Juergen Hoeller 8 years ago
parent a1e9459a43
commit cf0a0cd5d8
  1. 3
      spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java
  2. 13
      spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java

@ -942,7 +942,8 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
actualName = propertyName.substring(0, keyStart); actualName = propertyName.substring(0, keyStart);
} }
String key = propertyName.substring(keyStart + PROPERTY_KEY_PREFIX.length(), keyEnd); String key = propertyName.substring(keyStart + PROPERTY_KEY_PREFIX.length(), keyEnd);
if ((key.startsWith("'") && key.endsWith("'")) || (key.startsWith("\"") && key.endsWith("\""))) { if (key.length() > 1 && (key.startsWith("'") && key.endsWith("'")) ||
(key.startsWith("\"") && key.endsWith("\""))) {
key = key.substring(1, key.length() - 1); key = key.substring(1, key.length() - 1);
} }
keys.add(key); keys.add(key);

@ -202,6 +202,19 @@ public class BeanWrapperTests extends AbstractPropertyAccessorTests {
assertEquals("x", accessor.getPropertyValue("object.name")); assertEquals("x", accessor.getPropertyValue("object.name"));
} }
@Test
public void incompletelyQuotedKeyLeadsToPropertyException() {
TestBean target = new TestBean();
try {
BeanWrapper accessor = createAccessor(target);
accessor.setPropertyValue("[']", "foobar");
fail("Should throw exception on invalid property");
}
catch (NotWritablePropertyException ex) {
assertNull(ex.getPossibleMatches());
}
}
@SuppressWarnings("unused") @SuppressWarnings("unused")
private interface AliasedProperty { private interface AliasedProperty {

Loading…
Cancel
Save