Fix for issue #447. Ignore bean properties without a proper setter/getter

This commit is contained in:
tzarouali 2017-02-20 20:02:31 +00:00
parent 01bb93367f
commit 4d98a0069e
3 changed files with 35 additions and 1 deletions

View File

@ -69,7 +69,9 @@ public class ConfigBeanImpl {
try {
List<PropertyDescriptor> beanProps = new ArrayList<PropertyDescriptor>();
for (PropertyDescriptor beanProp : beanInfo.getPropertyDescriptors()) {
if (beanProp.getReadMethod() == null || beanProp.getWriteMethod() == null) {
if (beanProp.getReadMethod() == null
|| beanProp.getWriteMethod() == null
|| getField(clazz, beanProp.getName()) == null) {
continue;
}
beanProps.add(beanProp);

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 {