Skip to content

incorrect eval with deep (ThreadLocal context) #90

@sergeevik

Description

@sergeevik

example input

{
  "funcs": {
    "func": "$.a + $.b"
  },
  "a": 3,
  "b": 4
}

query $eval($.funcs.func)

expected result: 7
in jsonata online https://try.jsonata.org/fU8Heq6ee work correct

Image

simple code in test jsonata-java

  @Test
  public void testEvalDeep() {
    Object input = Json.parseJson("{" +
            "  \"funcs\": {" +
            "    \"func\": \"$.a + $.b\"" +
            "  }," +
            "  \"a\": 3," +
            "  \"b\": 4" +
            "}");
    var expression = Jsonata.jsonata("$eval($.funcs.func)");
    Object evaluate = expression.evaluate(input);
    Assertions.assertEquals(7, evaluate);
  }

result:

org.opentest4j.AssertionFailedError: 
Expected :7
Actual   :null

While debugging, I discovered that the input data is stored in a threadLocal.
When evaluatePath executes along a path, each new step stores a new input in the threadLocal. When the evaluatePath completes, the previous operation returns, and the input data remains from the evaluatePath operation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions