fix: validate list content to be values (#350)
validate list content Signed-off-by: Kavindu Dodanduwa <kavindudodanduwa@gmail.com> Co-authored-by: Justin Abrahms <jabrahms@ebay.com>
This commit is contained in:
parent
77890303c3
commit
d8e7d9e10c
|
|
@ -125,14 +125,27 @@ public class Value implements Cloneable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Check if this Value represents a List.
|
||||
* Check if this Value represents a List of Values.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isList() {
|
||||
return this.innerObject instanceof List
|
||||
&& (((List) this.innerObject).isEmpty()
|
||||
|| ((List) this.innerObject).get(0) instanceof Value);
|
||||
if (!(this.innerObject instanceof List)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<?> list = (List<?>) this.innerObject;
|
||||
if (list.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (Object obj : list) {
|
||||
if (!(obj instanceof Value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -134,4 +134,12 @@ public class ValueTest {
|
|||
fail("Unexpected exception occurred.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test public void valueConstructorValidateListInternals() {
|
||||
List<Object> list = new ArrayList<>();
|
||||
list.add(new Value("item"));
|
||||
list.add("item");
|
||||
|
||||
assertThrows(InstantiationException.class, ()-> new Value(list));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue