commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yang Wang (JIRA)" <>
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
                 Key: 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).

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");

        System.out.println(script.execute(new MapContext(m2)));
        System.out.println("Reached the end");

    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());


And the bug output is as follows:

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(
	at org.apache.commons.jexl3.parser.ASTJxltLiteral.jjtAccept(
	at org.apache.commons.jexl3.internal.Interpreter.visit(
	at org.apache.commons.jexl3.parser.ASTJexlScript.jjtAccept(
	at org.apache.commons.jexl3.internal.Interpreter.interpret(
	at org.apache.commons.jexl3.internal.Script.execute(
	at jexldemo2.DemoApplication.main(

This message was sent by Atlassian JIRA

View raw message