From 1ddcf3657bbc9e7d588e2d8e3dbe3af36cb41b14 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Wed, 27 Aug 2014 16:04:21 +0100 Subject: [PATCH] Be defensive about resolving properties in PropertySourcesPropertyValues --- .../boot/bind/PropertySourcesPropertyValues.java | 8 +++++++- .../bind/PropertySourcesPropertyValuesTests.java | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/bind/PropertySourcesPropertyValues.java b/spring-boot/src/main/java/org/springframework/boot/bind/PropertySourcesPropertyValues.java index eee990238c..6674651230 100644 --- a/spring-boot/src/main/java/org/springframework/boot/bind/PropertySourcesPropertyValues.java +++ b/spring-boot/src/main/java/org/springframework/boot/bind/PropertySourcesPropertyValues.java @@ -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()); } diff --git a/spring-boot/src/test/java/org/springframework/boot/bind/PropertySourcesPropertyValuesTests.java b/spring-boot/src/test/java/org/springframework/boot/bind/PropertySourcesPropertyValuesTests.java index 096a4540dd..b63afa058d 100644 --- a/spring-boot/src/test/java/org/springframework/boot/bind/PropertySourcesPropertyValuesTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/bind/PropertySourcesPropertyValuesTests.java @@ -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("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;