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
Utils.convertNulls mutates its input, so a nested evaluate in a custom function corrupts JSON nulls in the outer expression #124
Utils.convertNulls replaces Jsonata.NULL_VALUE with Java nullin place. Because Jsonata.evaluate calls it on its result (when output null conversion is on, the default), any nested evaluate inside a custom function rewrites data that the outer expression is still using. After that, JSON nulls in the outer data are treated as undefined.
Expected: ["null", "number"]
Actual: "number". The nested evaluate turned $t.p into [null, 1] (Java null), so the first element is treated as undefined.
Without the $echo($t) call, the result is correct.
On 0.9.10 (before 49df9f8, "Preserve JSON null when indexing into an array") the effect is also visible with indexing. For example, $exists($t.tests[0].parameters[0]) flips from true to false after the list was passed to such a custom function.
Cause
Utils.convertNulls(Object) and its Map/List overloads modify the structure passed to them (Utils.java, ~L207-243).
Jsonata.evaluate calls Utils.convertNulls(it) on the result (Jsonata.java, ~L2728). That result can share lists and maps with the caller's input or with another expression's live data.
Suggested fix
Have convertNulls return a converted copy, or copy only the containers that contain NULL_VALUE, instead of mutating its argument.
Activity