Skip to content

Fix multi-index JSONPath eval for primitive arrays - #7928

Open
Huang-404-Q wants to merge 1 commit into
alibaba:mainfrom
Huang-404-Q:fix/jsonpath-multi-index-primitive-array
Open

Huang-404-Q wants to merge 1 commit into
alibaba:mainfrom
Huang-404-Q:fix/jsonpath-multi-index-primitive-array

Conversation

@Huang-404-Q

Copy link
Copy Markdown

MultiIndexSegment.eval only handles List and Object[]. For primitive arrays it falls through and silently returns an empty JSONArray, while single-index eval, set and setCallback all work on the same array:

int[] array = {100, 101, 102, 103, 104, 105};
JSONPath.eval(array, "$[3,1]");  // []        expected [103,101]
JSONPath.eval(array, "$[0,-1]"); // []        expected [100,105]
JSONPath.eval(new Object[]{100, 101, 102, 103, 104, 105}, "$[3,1]"); // [103,101]

Fix: treat any array as an array via Array.getLength()/Array.get() instead of casting to Object[].

Added MultiIndexTest.eval_array. Without the fix it fails with expected: <[103,101]> but was: <[]>; with the fix all 12 tests in the class pass:

./mvnw -pl core -Dtest=MultiIndexTest test

MultiIndexSegment.eval only handled List and Object[], so $[3,1] on an
int[] silently returned an empty JSONArray. Single-index eval, set and
setCallback already support primitive arrays.

Use Array.getLength/Array.get for any array type.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants