You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Expression $[-1] throws ArrayIndexOutOfBoundsException on empty array input #106
$[-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 [].
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)
Activity
aeberhart commentedon Apr 30, 2026
thanks for reporting this. the issue is already fixed in the main branch (#78) but has not been pushed to maven yet (https://github.com/dashjoin/jsonata-java/milestone/9)