Uploaded image for project: 'Commons JEXL'
  1. Commons JEXL
  2. JEXL-241

NPE when script containing string interpolation executed in multiple threads

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.1
    • 3.2
    • None
    • 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

    Description

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

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

      Attachments

        Activity

          People

            henrib Henri Biestro
            ywangd Yang Wang
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: