You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by rm...@apache.org on 2018/05/29 10:16:09 UTC
svn commit: r1832441 - in /geronimo/components/config/trunk/impl/src:
main/java/org/apache/geronimo/config/cdi/ConfigInjectionBean.java
test/java/org/apache/geronimo/config/test/internal/ArrayTypeTest.java
Author: rmannibucau
Date: Tue May 29 10:16:09 2018
New Revision: 1832441
URL: http://svn.apache.org/viewvc?rev=1832441&view=rev
Log:
ensure default value is respected even for list/set
Modified:
geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigInjectionBean.java
geronimo/components/config/trunk/impl/src/test/java/org/apache/geronimo/config/test/internal/ArrayTypeTest.java
Modified: geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigInjectionBean.java
URL: http://svn.apache.org/viewvc/geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigInjectionBean.java?rev=1832441&r1=1832440&r2=1832441&view=diff
==============================================================================
--- geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigInjectionBean.java (original)
+++ geronimo/components/config/trunk/impl/src/main/java/org/apache/geronimo/config/cdi/ConfigInjectionBean.java Tue May 29 10:16:09 2018
@@ -138,7 +138,10 @@ public class ConfigInjectionBean<T> impl
// read the array type, convert it to a Set
ConfigImpl config = (ConfigImpl) getConfig();
String value = config.getValue(key);
- List<Object> elements = config.convertList(value, clazz);
+ if (value == null && ConfigExtension.isDefaultUnset(defaultValue)) {
+ return null;
+ }
+ List<Object> elements = config.convertList(value == null ? defaultValue : value, clazz);
return (T)new LinkedHashSet<>(elements);
}
@@ -147,7 +150,10 @@ public class ConfigInjectionBean<T> impl
// read the array type, convert it to a List
ConfigImpl config = (ConfigImpl) getConfig();
String value = config.getValue(key);
- return (T)config.convertList(value, clazz);
+ if (value == null && ConfigExtension.isDefaultUnset(defaultValue)) {
+ return null;
+ }
+ return (T)config.convertList(value == null ? defaultValue : value, clazz);
}
}
}
Modified: geronimo/components/config/trunk/impl/src/test/java/org/apache/geronimo/config/test/internal/ArrayTypeTest.java
URL: http://svn.apache.org/viewvc/geronimo/components/config/trunk/impl/src/test/java/org/apache/geronimo/config/test/internal/ArrayTypeTest.java?rev=1832441&r1=1832440&r2=1832441&view=diff
==============================================================================
--- geronimo/components/config/trunk/impl/src/test/java/org/apache/geronimo/config/test/internal/ArrayTypeTest.java (original)
+++ geronimo/components/config/trunk/impl/src/test/java/org/apache/geronimo/config/test/internal/ArrayTypeTest.java Tue May 29 10:16:09 2018
@@ -65,6 +65,7 @@ public class ArrayTypeTest extends Arqui
Assert.assertEquals(someBean.getMyconfig(), new int[]{1,2,3});
Assert.assertEquals(someBean.getIntValues(), asList(1,2,3));
Assert.assertEquals(someBean.getIntSet(), new LinkedHashSet<>(asList(1,2,3)));
+ Assert.assertEquals(someBean.getIntSetDefault(), new LinkedHashSet<>(asList(1,2,3)));
}
@Test
@@ -88,6 +89,10 @@ public class ArrayTypeTest extends Arqui
private Set<Integer> intSet;
@Inject
+ @ConfigProperty(name=SOME_KEY, defaultValue = "1,2,3")
+ private Set<Integer> intSetDefault;
+
+ @Inject
@ConfigProperty(name=SOME_KEY)
private String stringValue;
@@ -95,6 +100,10 @@ public class ArrayTypeTest extends Arqui
@ConfigProperty(name=SOME_OTHER_KEY)
private List<String> values;
+ public Set<Integer> getIntSetDefault() {
+ return intSetDefault;
+ }
+
public String getStringValue() {
return stringValue;
}