diff --git a/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java b/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java index b987fb56c80..cde668d48ce 100644 --- a/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java @@ -800,7 +800,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA /** * Recursively navigate to return a property accessor for the nested property path. - * @param propertyPath property property path, which may be nested + * @param propertyPath property path, which may be nested * @return a property accessor for the target bean */ @SuppressWarnings("unchecked") // avoid nested generic @@ -942,7 +942,8 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA actualName = propertyName.substring(0, keyStart); } 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); } keys.add(key); diff --git a/spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java b/spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java index 7a3232b1b19..a99bc92d89e 100644 --- a/spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -194,6 +194,19 @@ public class BeanWrapperTests extends AbstractPropertyAccessorTests { 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") private static class GetterBean { @@ -212,6 +225,7 @@ public class BeanWrapperTests extends AbstractPropertyAccessorTests { } } + @SuppressWarnings("unused") private static class IntelliBean {