Be defensive about resolving properties in PropertySourcesPropertyValues

pull/1487/merge
Dave Syer 10 years ago
parent 37aa532617
commit 1ddcf3657b

@ -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());
}

@ -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;

Loading…
Cancel
Save