Skip to content

Commit 464820d

Browse files
authored
fix: Do not throw null reference exception accessing a missing item. (#300)
Signed-off-by: Ryan Lamb <[email protected]>
1 parent 7459eaa commit 464820d

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/main/java/dev/openfeature/sdk/ImmutableStructure.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public Set<String> keySet() {
5050
@Override
5151
public Value getValue(String key) {
5252
Value value = this.attributes.get(key);
53-
return value.clone();
53+
return value != null ? value.clone() : null;
5454
}
5555

5656
/**

src/test/java/dev/openfeature/sdk/ImmutableStructureTest.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010
import java.util.Map;
1111
import java.util.Set;
1212

13-
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
14-
import static org.junit.jupiter.api.Assertions.assertEquals;
15-
import static org.junit.jupiter.api.Assertions.assertNotEquals;
16-
import static org.junit.jupiter.api.Assertions.assertNotSame;
17-
import static org.junit.jupiter.api.Assertions.assertTrue;
13+
import static org.junit.jupiter.api.Assertions.*;
1814

1915
class ImmutableStructureTest {
2016
@Test void noArgShouldContainEmptyAttributes() {
@@ -108,4 +104,11 @@ void ModifyingTheValuesReturnByTheKeySetMethodShouldNotModifyTheUnderlyingImmuta
108104
keys.remove("key1");
109105
assertEquals(2, structure.keySet().size());
110106
}
107+
108+
@Test
109+
void GettingAMissingValueShouldReturnNull() {
110+
ImmutableStructure structure = new ImmutableStructure();
111+
Object value = structure.getValue("missing");
112+
assertNull(value);
113+
}
111114
}

0 commit comments

Comments
 (0)