Be defensive about resolving properties in PropertySourcesPropertyValues

This commit is contained in:
Dave Syer 2014-08-27 16:04:21 +01:00
parent 37aa532617
commit 1ddcf3657b
2 changed files with 22 additions and 1 deletions

View File

@ -152,7 +152,13 @@ public class PropertySourcesPropertyValues implements PropertyValues {
private void processDefaultPropertySource(PropertySource<?> source,
PropertySourcesPropertyResolver resolver, String[] includes, String[] exacts) {
for (String propertyName : exacts) {
Object value = resolver.getProperty(propertyName);
Object value = null;
try {
value = resolver.getProperty(propertyName, Object.class);
}
catch (RuntimeException ex) {
// Probably could not convert to Object, weird, but ignoreable
}
if (value == null) {
value = source.getProperty(propertyName.toUpperCase());
}

View File

@ -138,6 +138,21 @@ public class PropertySourcesPropertyValuesTests {
assertEquals("bar", target.getName());
}
@Test
public void testPlaceholdersErrorInNonEnumerable() {
TestBean target = new TestBean();
DataBinder binder = new DataBinder(target);
this.propertySources.addFirst(new PropertySource<Object>("application", "STUFF") {
@Override
public Object getProperty(String name) {
return new Object();
}
});
binder.bind(new PropertySourcesPropertyValues(this.propertySources, null,
Collections.singleton("name")));
assertEquals(null, target.getName());
}
public static class TestBean {
private String name;