Skip to content

Commit

Permalink
fix: Do not throw null reference exception accessing a missing item. (#…
Browse files Browse the repository at this point in the history
…300)

Signed-off-by: Ryan Lamb <[email protected]>
  • Loading branch information
kinyoklion authored Feb 16, 2023
1 parent 7459eaa commit 464820d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/java/dev/openfeature/sdk/ImmutableStructure.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Set<String> keySet() {
@Override
public Value getValue(String key) {
Value value = this.attributes.get(key);
return value.clone();
return value != null ? value.clone() : null;
}

/**
Expand Down
13 changes: 8 additions & 5 deletions src/test/java/dev/openfeature/sdk/ImmutableStructureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
import java.util.Map;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

class ImmutableStructureTest {
@Test void noArgShouldContainEmptyAttributes() {
Expand Down Expand Up @@ -108,4 +104,11 @@ void ModifyingTheValuesReturnByTheKeySetMethodShouldNotModifyTheUnderlyingImmuta
keys.remove("key1");
assertEquals(2, structure.keySet().size());
}

@Test
void GettingAMissingValueShouldReturnNull() {
ImmutableStructure structure = new ImmutableStructure();
Object value = structure.getValue("missing");
assertNull(value);
}
}

0 comments on commit 464820d

Please sign in to comment.