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

Henri Biestro closed JEXL-318.
------------------------------

> Annotation processing may fail in lexical mode
> ----------------------------------------------
>
>                 Key: JEXL-318
>                 URL: https://issues.apache.org/jira/browse/JEXL-318
>             Project: Commons JEXL
>          Issue Type: Bug
>    Affects Versions: 3.1
>            Reporter: Dmitri Blinov
>            Priority: Major
>             Fix For: 3.2
>
>
> I fave found that the annotation processing under certain conditions may lead 
> to NPE
> {code:java}
>     public static class OptAnnotationContext extends JexlEvalContext 
> implements JexlContext.AnnotationProcessor {
>         @Override
>         public Object processAnnotation(String name, Object[] args, 
> Callable<Object> statement) throws Exception {
>             JexlOptions options = this.getEngineOptions();
>             // transient side effect for strict
>             if ("scale".equals(name)) {
>                 int scale = options.getMathScale();
>                 int newScale = (Integer) args[0];
>                 options.setMathScale(newScale);
>                 try {
>                     return statement.call();
>                 } finally {
>                     options.setMathScale(scale);
>                 }
>             }
>             return statement.call();
>         }
>     }
>     @Test
>     public void testAnnotation() throws Exception {
>         JexlFeatures f = new JexlFeatures();
>         f.lexical(true);
>         JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
>         JexlScript script = jexl.createScript("@scale(13) @test var i = 42");
>         JexlContext jc = new OptAnnotationContext();
>         Object result = script.execute(jc);
>         Assert.assertEquals(result, 42);
>     }
>  {code}
> This is because new instance of Interpeter is created to process annotation 
> under certain conditions, and this new instance does not inherit the current 
> lexical block. Furthermore, the constructor of InterperterBase 
> {{InterpreterBase(InterpreterBase ii, JexlArithmetic jexla)}} now silently 
> ignores JexlArithmetic passed to it, which is possibly another bug.
> As a suggestion, can we refactor the code to simply make JexlArithmetic non 
> final in InterpreterBase? There would be no need to create new instance of 
> Interpeter and complicate code with sync-state code?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to