Skip to content

Commit 7541e9c

Browse files
committed
NPE in $sort when lhs of the comparison evaluates to NULL #68
1 parent f2a8763 commit 7541e9c

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/main/java/com/dashjoin/jsonata/Functions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1953,7 +1953,9 @@ public static List sort(List arr, Object comparator) {
19531953
@Override
19541954
public int compare(Object o1, Object o2) {
19551955
try {
1956-
boolean swap = (boolean) funcApply(comparator, Arrays.asList(o1, o2));
1956+
Boolean swap = toBoolean(funcApply(comparator, Arrays.asList(o1, o2)));
1957+
if (swap == null)
1958+
return 0;
19571959
if (swap)
19581960
return 1;
19591961
else

src/test/java/com/dashjoin/jsonata/ArrayTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public void testSort() {
4343
Assertions.assertEquals(Arrays.asList(Map.of("x", 1), Map.of("x", 2)), expr.evaluate(null));
4444
}
4545

46-
@Disabled
4746
@Test
4847
public void testSortNull() {
4948
Jsonata expr = jsonata("$sort([{'x': 2}, {'x': 1}], function($l, $r){$l.y > $r.y})");

0 commit comments

Comments
 (0)