Merge pull request #454 from tzarouali/issue-447

Fix for issue #447. Ignore bean properties without a proper setter/ge…
This commit is contained in:
Havoc Pennington 2017-02-20 16:36:34 -05:00 committed by GitHub
commit 409981cb33
3 changed files with 33 additions and 1 deletions

View File

@ -277,7 +277,7 @@ public class ConfigBeanImpl {
private static boolean isOptionalProperty(Class beanClass, PropertyDescriptor beanProp) {
Field field = getField(beanClass, beanProp.getName());
return (field.getAnnotationsByType(Optional.class).length > 0);
return field != null && (field.getAnnotationsByType(Optional.class).length > 0);
}
private static Field getField(Class beanClass, String fieldName) {

View File

@ -0,0 +1,24 @@
package beanconfig;
public class DifferentFieldNameFromAccessorsConfig {
private String customStringField;
private Long number;
public String getStringField() {
return customStringField;
}
public void setStringField(String stringField) {
this.customStringField = stringField;
}
public Long getNumber() {
return number;
}
public void setNumber(Long number) {
this.number = number;
}
}

View File

@ -237,6 +237,14 @@ class ConfigBeanFactoryTest extends TestUtils {
assertTrue("error about the right property", e.getMessage.contains("'map'"))
}
@Test
def testDifferentFieldNameFromAccessors(): Unit = {
val e = intercept[ConfigException.ValidationFailed] {
ConfigBeanFactory.create(ConfigFactory.empty(), classOf[DifferentFieldNameFromAccessorsConfig])
}
assertTrue("only one missing value error", e.getMessage.contains("No setting"))
}
private def loadConfig(): Config = {
val configIs: InputStream = this.getClass().getClassLoader().getResourceAsStream("beanconfig/beanconfig01.conf")
try {