commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin McLaughlin (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (JEXL-241) NPE when script containing string interpolation executed in multiple threads
Date Thu, 07 Dec 2017 15:43:00 GMT

    [ https://issues.apache.org/jira/browse/JEXL-241?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16282019#comment-16282019
] 

Kevin McLaughlin commented on JEXL-241:
---------------------------------------

Take your time :).  Workaround is not difficult.

{code:java}

    // workaround https://issues.apache.org/jira/browse/JEXL-241.  Remove when 3.2 is released.

    private class Jexl241Builder extends JexlBuilder {
        @Override
        public JexlEngine create() {
            return new Jexl241Engine(this);
        }
    }

    private class Jexl241Engine extends Engine {
        Jexl241Engine(JexlBuilder conf) {
            super(conf);
        }

        @Override
        protected TemplateEngine jxlt() {
            TemplateEngine e = jxlt;
            if (e == null) {
                synchronized(this) {
                    e = jxlt;
                    if (e == null) {
                        e = new TemplateEngine(this, true, 0, '$', '#');
                        jxlt = e;
                    }
                }
            }
            return e;
        }
{code}


> NPE when script containing string interpolation executed in multiple threads
> ----------------------------------------------------------------------------
>
>                 Key: JEXL-241
>                 URL: https://issues.apache.org/jira/browse/JEXL-241
>             Project: Commons JEXL
>          Issue Type: Bug
>    Affects Versions: 3.1
>         Environment: Centos Linux 7.2.1511
> openjdk version "1.8.0_101"
> OpenJDK Runtime Environment (build 1.8.0_101-b13)
> OpenJDK 64-Bit Server VM (build 25.101-b13, mixed mode)
> Gradle dependency for JEXL is org.apache.commons:commons-jexl3:3.1
>            Reporter: Yang Wang
>            Assignee: Henri Biestro
>            Priority: Minor
>             Fix For: 3.2
>
>
> When a script containing string interpolation is executed in multiple threads, a "NullPointerException"
is sometimes thrown (other times it may hang or it may run successfully).
> The following is a sample program that can produce the bug (you may need to run it for
a few times to encounter the bug).
> {code:java}
> package jexldemo2;
> import org.apache.commons.jexl3.JexlBuilder;
> import org.apache.commons.jexl3.JexlScript;
> import org.apache.commons.jexl3.MapContext;
> import java.util.HashMap;
> import java.util.Map;
> import java.util.concurrent.ExecutorService;
> import java.util.concurrent.Executors;
> public class DemoApplication {
>     private static ExecutorService pool;
>     private static JexlScript script = new JexlBuilder().create().createScript("`${item}`");
>     public static void main(String[] args) throws InterruptedException {
>         pool = Executors.newFixedThreadPool(4);
>         Map<String, Object> m1 = new HashMap<>();
>         m1.put("item", "A");
>         Map<String, Object> m2 = new HashMap<>();
>         m2.put("item", "B");
>         handle(m1);
>         System.out.println(script.execute(new MapContext(m2)));
>         System.out.println("Reached the end");
>         pool.shutdown();
>     }
>     private static void handle(Map<String, Object> payload) {
>         System.out.printf("START: %s\n", Thread.currentThread());
>         pool.submit(() -> System.out.println(script.execute(new MapContext(payload))));
>         System.out.printf("STOP: %s\n", Thread.currentThread());
>     }
> }
> {code}
> And the bug output is as follows:
> {noformat}
> START: Thread[main,5,main]
> STOP: Thread[main,5,main]
> Exception in thread "main" java.lang.NullPointerException
> 	at org.apache.commons.jexl3.internal.Interpreter.visit(Interpreter.java:1818)
> 	at org.apache.commons.jexl3.parser.ASTJxltLiteral.jjtAccept(ASTJxltLiteral.java:50)
> 	at org.apache.commons.jexl3.internal.Interpreter.visit(Interpreter.java:892)
> 	at org.apache.commons.jexl3.parser.ASTJexlScript.jjtAccept(ASTJexlScript.java:55)
> 	at org.apache.commons.jexl3.internal.Interpreter.interpret(Interpreter.java:186)
> 	at org.apache.commons.jexl3.internal.Script.execute(Script.java:178)
> 	at jexldemo2.DemoApplication.main(DemoApplication.java:26)
> A
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message