Skip to content

Commit

Permalink
isList check of Value checks type of list
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Grassian <robert.grassian@split.io>
  • Loading branch information
rgrassian-split committed Sep 13, 2022
1 parent 89ea363 commit 1e90c48
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/dev/openfeature/javasdk/Value.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ public boolean isStructure() {
* @return boolean
*/
public boolean isList() {
return this.innerObject instanceof List;
return this.innerObject instanceof List
&& (((List) this.innerObject).isEmpty()
|| ((List) this.innerObject).get(0) instanceof Value);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/dev/openfeature/javasdk/ValueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,16 @@ class Something {}
assertTrue(value.isList());
assertEquals(ITEM_VALUE, value.asList().get(0).asString());
}

@Test public void listMustBeOfValues() {
String item = "item";
List<String> list = new ArrayList<>();
list.add(item);
try {
new Value((Object) list);
fail("Should fail due to creation of list of non-values.");
} catch (InstantiationException e) {
assertEquals("Invalid value type: class java.util.ArrayList", e.getMessage());
}
}
}

0 comments on commit 1e90c48

Please sign in to comment.