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 2025/08/02 05:59:00 UTC

[jira] [Resolved] (JEXL-442) Local variables are not resolved in interpolation string expression.

     [ https://issues.apache.org/jira/browse/JEXL-442?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Biestro resolved JEXL-442.
--------------------------------
    Resolution: Fixed

Create expression-parser sharing scope information with outer script parser to process interpolation expressions; ensures that local variables are correctly resolved at parsing time (not evaluation time).

Fixed [5b0d21|https://github.com/apache/commons-jexl/commit/45b0d219c149b6ca539f3b9b43cdf93eb2fb0c16]

> Local variables are not resolved in interpolation string expression.
> --------------------------------------------------------------------
>
>                 Key: JEXL-442
>                 URL: https://issues.apache.org/jira/browse/JEXL-442
>             Project: Commons JEXL
>          Issue Type: Bug
>    Affects Versions: 3.5.0
>            Reporter: Xu Pengcheng
>            Assignee: Henri Biestro
>            Priority: Major
>             Fix For: 3.6.0
>
>
> The following code throws an exception: JexlExample.main:24@3:1 variable 'x' is undefined
> {code:java}
> JexlBuilder jexlBuilder = new JexlBuilder();
> JexlEngine jexl = jexlBuilder.create();
> JexlContext context = new MapContext();
> String code = """
>   var x = 'hello';
>   function test() {
>     return `${x}`
>   }
>   test();
> """;
> JexlScript script = jexl.createScript(code);
> Object result = script.execute(context);
> System.out.println("Expression Result: " + result);{code}
> but if I change to 
> {code:java}
> return x; {code}
> which works.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)