commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yang Wang (JIRA)" <j...@apache.org>
Subject [jira] [Created] (JEXL-241) NPE when script containing string interpolation executed in multiple threads
Date Mon, 16 Oct 2017 00:29:00 GMT
Yang Wang created JEXL-241:
------------------------------

             Summary: 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
            Priority: Minor


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