Skip to content

Commit 7735274

Browse files
committed
fix: Fix bug in validation of empty composite values.
The isEmptyComposite() test needs to be first, otherwise obj instanceof XObject will be true and the method will return the wrong result.
1 parent adf6007 commit 7735274

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

module/jsonurl-jsonorg/src/main/java/org/jsonurl/jsonorg/JsonOrgValueFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ default boolean isValid(Set<ValueType> types, Object value) {
212212
if (value instanceof Boolean) {
213213
return types.contains(ValueType.BOOLEAN);
214214
}
215+
if (isEmptyComposite(value)) {
216+
return types.contains(ValueType.OBJECT)
217+
|| types.contains(ValueType.ARRAY);
218+
}
215219
if (value instanceof JSONArray) {
216220
return types.contains(ValueType.ARRAY);
217221
}
@@ -221,10 +225,6 @@ default boolean isValid(Set<ValueType> types, Object value) {
221225
if (isNull(value)) {
222226
return types.contains(ValueType.NULL);
223227
}
224-
if (isEmptyComposite(value)) {
225-
return types.contains(ValueType.OBJECT)
226-
|| types.contains(ValueType.ARRAY);
227-
}
228228
return false;
229229
}
230230
}

module/jsonurl-jsr374/src/main/java/org/jsonurl/jsonp/JsonpValueFactory.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,10 @@ default boolean isValid(Set<ValueType> types, JsonValue value) {
356356
if (value == JsonValue.FALSE || value == JsonValue.TRUE) {
357357
return types.contains(ValueType.BOOLEAN);
358358
}
359+
if (isEmptyComposite(value)) {
360+
return types.contains(ValueType.OBJECT)
361+
|| types.contains(ValueType.ARRAY);
362+
}
359363
if (value instanceof JsonArray) {
360364
return types.contains(ValueType.ARRAY);
361365
}
@@ -365,10 +369,6 @@ default boolean isValid(Set<ValueType> types, JsonValue value) {
365369
if (JsonValue.NULL == value) {
366370
return types.contains(ValueType.NULL);
367371
}
368-
if (isEmptyComposite(value)) {
369-
return types.contains(ValueType.OBJECT)
370-
|| types.contains(ValueType.ARRAY);
371-
}
372372
return false;
373373
}
374374
}

0 commit comments

Comments
 (0)