Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-5706

JSR 223 invokeFunction broken in 2.0.2 - regression

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 2.0.2
    • 2.0.4, 1.8.9
    • GroovyScriptEngine
    • None
    • Reproduced with Java 6 and Java 7.

    Description

      The below script works in Groovy 2.0.1 and earlier but stopped working in Groovy 2.0.2. I invoke a global glosure named "helloWorld". I use two different strings named "helloWorld". Sometimes this works, sometimes this fails.

      I suspect the problem is in GroovyScriptEngineImpl. The globalClosures map was changed in 2.0.2. It is no longer a java.util.Map but is some other map (ManagedConcurrentMap). I suspect it may be a problem with the map using System.identityHashCode() is its mechanism for looking up Closures. Obviously, any string named "helloWorld" should work here.

      SEVERITY:
      This problem causes breakage in real applications that use JSR 223 API for Groovy and other script engines. A user would need to roll back to 2.0.1.

      EXAMPLE:

      import javax.script.Compilable;
      import javax.script.CompiledScript;
      import javax.script.Invocable;
      import javax.script.ScriptEngine;
      import javax.script.ScriptEngineManager;
      
      public class HelloWorld {
          public static void main(String[] args) throws Exception {
              String script = "void helloWorld() { println \"Hello World\" }";
              ScriptEngineManager factory = new ScriptEngineManager();
              ScriptEngine engine = factory.getEngineByName("groovy");
              CompiledScript compiled = ((Compilable) engine).compile(script);
              compiled.eval();
              String name = "helloWorld";
              String name2 = new String(name.toCharArray());
              if (!name.equals(name2)) {
                  System.out.println("should be equal!");
              }
              ((Invocable) engine).invokeFunction(name);   // works
              ((Invocable) engine).invokeFunction(name);   // still works
              ((Invocable) engine).invokeFunction(name2);  // fails since Groovy 2.0.2
          }
      }
      

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            benken_parasoft Joseph Benken
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: