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

Script calls within scripts may fail with number arguments

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.1.1
    • 2.1.2, 3.0
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: