Title
$[-1] throws ArrayIndexOutOfBoundsException when evaluating against an empty array []
Description
The expression $[-1] (to get the last element of an array) throws an ArrayIndexOutOfBoundsException when evaluated against an empty array [], instead of returning no match/null as expected and as seen in the official JSONata online evaluator.
Steps to Reproduce
- Define the expression
$[-1].
- Evaluate the expression against an empty array
[].
Sample Code:
import com.dashjoin.jsonata.Jsonata;
import java.util.List;
public class UnitTest {
public static void main(String[] args) {
var jsonata = Jsonata.jsonata("$[-1]");
System.out.println(jsonata.evaluate(List.of()));
}
}
Expected Behavior
The expression should return null or no match (consistent with the behavior in the official JSONata Exerciser) without throwing an exception.
Actual Behavior
The evaluation throws an ArrayIndexOutOfBoundsException:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 0
at java.base/java.util.ImmutableCollections$ListN.get(ImmutableCollections.java:687)
at com.dashjoin.jsonata.Jsonata.evaluateFilter(Jsonata.java:503)
at com.dashjoin.jsonata.Jsonata._evaluate(Jsonata.java:212)
at com.dashjoin.jsonata.Jsonata.evaluate(Jsonata.java:131)
at com.dashjoin.jsonata.Jsonata.evaluate(Jsonata.java:2583)
at com.dashjoin.jsonata.Jsonata.evaluate(Jsonata.java:2544)
at com.example.demo.UnitTest.main(UnitTest.java:17)
Title
$[-1]throwsArrayIndexOutOfBoundsExceptionwhen evaluating against an empty array[]Description
The expression
$[-1](to get the last element of an array) throws anArrayIndexOutOfBoundsExceptionwhen evaluated against an empty array[], instead of returningno match/nullas expected and as seen in the official JSONata online evaluator.Steps to Reproduce
$[-1].[].Sample Code:
Expected Behavior
The expression should return
nullorno match(consistent with the behavior in the official JSONata Exerciser) without throwing an exception.Actual Behavior
The evaluation throws an
ArrayIndexOutOfBoundsException: