mirror of
https://github.com/lightbend/config.git
synced 2025-01-15 14:50:23 +08:00
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:
commit
409981cb33
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user