Skip to content

Commit 1ddcf36

Browse files
author
Dave Syer
committed
Be defensive about resolving properties in PropertySourcesPropertyValues
1 parent 37aa532 commit 1ddcf36

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,13 @@ private Collection<PropertySource<?>> extractSources(CompositePropertySource com
152152
private void processDefaultPropertySource(PropertySource<?> source,
153153
PropertySourcesPropertyResolver resolver, String[] includes, String[] exacts) {
154154
for (String propertyName : exacts) {
155-
Object value = resolver.getProperty(propertyName);
155+
Object value = null;
156+
try {
157+
value = resolver.getProperty(propertyName, Object.class);
158+
}
159+
catch (RuntimeException ex) {
160+
// Probably could not convert to Object, weird, but ignoreable
161+
}
156162
if (value == null) {
157163
value = source.getProperty(propertyName.toUpperCase());
158164
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,21 @@ public void testPlaceholdersBindingWithError() {
138138
assertEquals("bar", target.getName());
139139
}
140140

141+
@Test
142+
public void testPlaceholdersErrorInNonEnumerable() {
143+
TestBean target = new TestBean();
144+
DataBinder binder = new DataBinder(target);
145+
this.propertySources.addFirst(new PropertySource<Object>("application", "STUFF") {
146+
@Override
147+
public Object getProperty(String name) {
148+
return new Object();
149+
}
150+
});
151+
binder.bind(new PropertySourcesPropertyValues(this.propertySources, null,
152+
Collections.singleton("name")));
153+
assertEquals(null, target.getName());
154+
}
155+
141156
public static class TestBean {
142157
private String name;
143158

0 commit comments

Comments
 (0)