Skip to content

Commit d8e7d9e

Browse files
fix: validate list content to be values (#350)
validate list content Signed-off-by: Kavindu Dodanduwa <[email protected]> Co-authored-by: Justin Abrahms <[email protected]>
1 parent 7789030 commit d8e7d9e

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

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

+17-4
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,27 @@ public boolean isStructure() {
125125
}
126126

127127
/**
128-
* Check if this Value represents a List.
128+
* Check if this Value represents a List of Values.
129129
*
130130
* @return boolean
131131
*/
132132
public boolean isList() {
133-
return this.innerObject instanceof List
134-
&& (((List) this.innerObject).isEmpty()
135-
|| ((List) this.innerObject).get(0) instanceof Value);
133+
if (!(this.innerObject instanceof List)) {
134+
return false;
135+
}
136+
137+
List<?> list = (List<?>) this.innerObject;
138+
if (list.isEmpty()) {
139+
return true;
140+
}
141+
142+
for (Object obj : list) {
143+
if (!(obj instanceof Value)) {
144+
return false;
145+
}
146+
}
147+
148+
return true;
136149
}
137150

138151
/**

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

+8
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,12 @@ class Something {}
134134
fail("Unexpected exception occurred.", e);
135135
}
136136
}
137+
138+
@Test public void valueConstructorValidateListInternals() {
139+
List<Object> list = new ArrayList<>();
140+
list.add(new Value("item"));
141+
list.add("item");
142+
143+
assertThrows(InstantiationException.class, ()-> new Value(list));
144+
}
137145
}

0 commit comments

Comments
 (0)