Skip to content

Commit 3acf6ec

Browse files
committed
fix(common): add guards to prevent wrapping single collection values...
...again in another collection in HashMapOptions
1 parent b45b639 commit 3acf6ec

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

commons/com.b2international.commons/src/com/b2international/commons/options/HashMapOptions.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public <T> T get(Enum<?> key, Class<T> expectedType) {
130130
@SuppressWarnings("unchecked")
131131
public final <T> Collection<T> getCollection(String key, Class<T> type) {
132132
final Object value = get(key);
133-
if (type.isInstance(value)) {
133+
if (type.isInstance(value) && (value != null && !Collection.class.isAssignableFrom(value.getClass()))) {
134134
return Collections.singleton(type.cast(value));
135135
} else {
136136
final Collection<Object> collection = get(key, Collection.class);
@@ -154,7 +154,7 @@ public <T> Collection<T> getCollection(Enum<?> key, Class<T> type) {
154154
@SuppressWarnings("unchecked")
155155
public final <T> Set<T> getSet(String key, Class<T> type) {
156156
final Object value = get(key);
157-
if (type.isInstance(value)) {
157+
if (type.isInstance(value) && (value != null && !Set.class.isAssignableFrom(value.getClass()))) {
158158
return Collections.singleton(type.cast(value));
159159
} else {
160160
final Set<Object> set = get(key, Set.class);
@@ -178,7 +178,7 @@ public <T> Set<T> getSet(Enum<?> key, Class<T> type) {
178178
@SuppressWarnings("unchecked")
179179
public final <T> List<T> getList(String key, Class<T> type) {
180180
final Object value = get(key);
181-
if (type.isInstance(value)) {
181+
if (type.isInstance(value) && (value != null && !List.class.isAssignableFrom(value.getClass()))) {
182182
return Collections.singletonList(type.cast(value));
183183
} else {
184184
final List<Object> list = get(key, List.class);

0 commit comments

Comments
 (0)