Uploaded image for project: 'Commons JEXL'
  1. Commons JEXL
  2. JEXL-136

Script calls within scripts may fail with number arguments

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.1
    • Fix Version/s: 2.1.2, 3.0
    • Labels:
      None

      Description

      Jexl attempts to narrow arguments when solving function names; unfortunately,
      this may cause issues when the function is a script and the argument type is expected to remain untouched.

      The map key in the following code is an Integer; by calling the function fn01, the interpreter fails to find a method and retries after 'narrowing' the argument which becomes a Byte. The Byte is not equal to the Integer map key with the same value; the test fails.

             @Test
              public void test136() throws Exception {
                  JexlEngine jexl = new Engine();
                  JexlContext jc = new MapContext();
                  JexlScript script;
                  JexlExpression expr;
                  Object result;
      
                  script = jexl.createScript("var x = $TAB[idx]; return x;", "idx");
                  jc.set("fn01", script);
      
                  script = jexl.createScript("$TAB = { 1:11, 2:22, 3:33}; IDX=2;");
                  script.execute(jc);
      
                  expr = jexl.createExpression("fn01(IDX)");
                  result = expr.evaluate(jc);
                  assertEquals("EXPR01 result", 22, result);
              }
      

        Attachments

          Activity

            People

            • Assignee:
              henrib Henri Biestro
              Reporter:
              henrib Henri Biestro
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: