Browse Source

Be defensive about resolving properties in PropertySourcesPropertyValues

pull/1487/merge
Dave Syer 12 years ago
parent
commit
1ddcf3657b
  1. 8
      spring-boot/src/main/java/org/springframework/boot/bind/PropertySourcesPropertyValues.java
  2. 15
      spring-boot/src/test/java/org/springframework/boot/bind/PropertySourcesPropertyValuesTests.java

8
spring-boot/src/main/java/org/springframework/boot/bind/PropertySourcesPropertyValues.java

@ -152,7 +152,13 @@ public class PropertySourcesPropertyValues implements PropertyValues { @@ -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());
}

15
spring-boot/src/test/java/org/springframework/boot/bind/PropertySourcesPropertyValuesTests.java

@ -138,6 +138,21 @@ public class PropertySourcesPropertyValuesTests { @@ -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