You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Henri Biestro (JIRA)" <ji...@apache.org> on 2012/07/09 21:05:35 UTC

[jira] [Created] (JEXL-136) Script calls within scripts may fail with number arguments

Henri Biestro created JEXL-136:
----------------------------------

             Summary: Script calls within scripts may fail with number arguments
                 Key: JEXL-136
                 URL: https://issues.apache.org/jira/browse/JEXL-136
             Project: Commons JEXL
          Issue Type: Bug
    Affects Versions: 2.1.1
            Reporter: Henri Biestro
            Assignee: Henri Biestro
             Fix For: 2.1.2, 3.0


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.

{code}
       @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);
        }
{code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (JEXL-136) Script calls within scripts may fail with number arguments

Posted by "Henri Biestro (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/JEXL-136?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Biestro resolved JEXL-136.
--------------------------------

    Resolution: Fixed

Changed logic of Interpreter.call to narrow only after trying all other possibilities.


jexl2/src/main/java/org/apache/commons/jexl2/Interpreter.java
jexl2/src/test/java/org/apache/commons/jexl2/IssuesTest.java

Committed revision 1359338.
                
> Script calls within scripts may fail with number arguments
> ----------------------------------------------------------
>
>                 Key: JEXL-136
>                 URL: https://issues.apache.org/jira/browse/JEXL-136
>             Project: Commons JEXL
>          Issue Type: Bug
>    Affects Versions: 2.1.1
>            Reporter: Henri Biestro
>            Assignee: Henri Biestro
>             Fix For: 2.1.2, 3.0
>
>
> 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.
> {code}
>        @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);
>         }
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira