Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 80b6410

Browse files
committed
#429 Fixing NPE issue in MapPropertiesSource
1 parent ddeec85 commit 80b6410

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/main/java/com/marklogic/appdeployer/util/MapPropertiesSource.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ public MapPropertiesSource(Map<String, String> map) {
2121
@Override
2222
public Properties getProperties() {
2323
Properties props = new Properties();
24-
props.putAll(map);
24+
for (String key : map.keySet()) {
25+
String value = map.get(key);
26+
if (value != null) {
27+
props.setProperty(key, value);
28+
}
29+
}
2530
return props;
2631
}
2732
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.marklogic.appdeployer.util;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
import java.util.HashMap;
7+
import java.util.Map;
8+
import java.util.Properties;
9+
10+
public class MapPropertiesSourceTest extends Assert {
11+
12+
@Test
13+
public void propertiesWithNull() {
14+
Map<String, String> map = new HashMap<>();
15+
map.put("hello", "world");
16+
map.put("isNull", null);
17+
18+
Properties props = new MapPropertiesSource(map).getProperties();
19+
assertEquals("world", props.getProperty("hello"));
20+
assertFalse(props.containsKey("isNull"));
21+
}
22+
}

0 commit comments

Comments
 (0)