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

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

Grammar change to consider a try/catch as a lexical node (so local variables 
can be declared without clashing with outer scope, same as try-with-resource).

Commit 
[1934f2b|https://github.com/apache/commons-jexl/commit/1934f2bd3a392382ee525bd649da10eda0e9ef2d]

> Parse error with variables declared in a catch clause
> -----------------------------------------------------
>
>                 Key: JEXL-431
>                 URL: https://issues.apache.org/jira/browse/JEXL-431
>             Project: Commons JEXL
>          Issue Type: Bug
>    Affects Versions: 3.4.0
>            Reporter: Vincent Bussol
>            Assignee: Henri Biestro
>            Priority: Major
>             Fix For: 3.4.1
>
>
> A variable defined in a catch clause cannot be reused in the same block.
> The following scripts are not allowed by the parser:
> {code:java}
> try {
>   // do stuff
> } catch (let error) {
>   // manage error
> }
> let error = 'hello error';{code}
> Or:
> {code:java}
> try {
>   // do stuff
> } catch (let error) {
>   // manage error
> }
> try {
>   // do stuff
> } catch (let error) {
>   // manage error
> }{code}
> Both cases end with a parsing error:
> {code:java}
> error: variable is already declared {code}
> A failing test can look like:
> {code:java}
> JexlEngine jexl = new JexlBuilder().create();
> final String src = "let x = 0; try { x += 19 } catch (let error) { return 169 
> } try { x += 23 } catch (let error) { return 169 }";
> final JexlScript script = jexl.createScript(src);
> assertNotNull(script);
> final Object result = script.execute(null);
> assertEquals(42, result); {code}
> At runtime it works fine.
> A try-with-resources is working fine as well:
> {code:java}
> try (let closeable = open()) {
>   // IO stuff
> }
> try (let closeable = open()) {
>   // IO stuff
> }{code}



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

Reply via email to