scripting
  1. scripting
  2. SCRIPTING-41

problem with imports handling in Groovy engine

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: current
    • Fix Version/s: milestone 1
    • Component/s: www
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      41

      Description

      Hi
      There are two problems in the Groovy engine:
      1. engine.eval("import <anything here>"); results in NullPointerException.
      2. engine forgets all the imports between eval() calls.

      (there are no such problems in the BeanShell BTW)

      Here's a test case, it shouldn't produce any errors IMHO:

      import javax.script.ScriptEngine;
      import javax.script.ScriptEngineManager;

      public class BugTest {
      private static ScriptEngine engine;

      public static void main(final String[] args) throws Exception

      { final ScriptEngineManager factory = new ScriptEngineManager(); engine = factory.getEngineByName("groovy"); test("import java.beans.*"); test("import java.beans.*;1+2"); test("new Encoder()"); }

      private static void test(final String script) {
      try

      { System.out.println(script + " = " + engine.eval(script)); }

      catch (Exception e)

      { System.err.println("Error evaluating '" + script + "':"); e.printStackTrace(); }

      }
      }

        Activity

        Hide
        sstevenson638 added a comment -

        I have the same issue. In groovy 1.8.1 the imports seem to work, but it still forgets the imports between calls to eval().

        I had this same problem several years ago when experimenting with groovy and found that if I used either the GroovyEngine or GroovyShell one of those remembers imports between calls to eval(). The implementation of ScriptEngine in JSR223 seems to do everything from scratch and doesn't rely on GroovyEngine or GroovyShell.

        Looks like I may have to write my own implementation of ScriptEngine that wraps a GroovyEngine or GroovyShell.

        Show
        sstevenson638 added a comment - I have the same issue. In groovy 1.8.1 the imports seem to work, but it still forgets the imports between calls to eval(). I had this same problem several years ago when experimenting with groovy and found that if I used either the GroovyEngine or GroovyShell one of those remembers imports between calls to eval(). The implementation of ScriptEngine in JSR223 seems to do everything from scratch and doesn't rely on GroovyEngine or GroovyShell. Looks like I may have to write my own implementation of ScriptEngine that wraps a GroovyEngine or GroovyShell.

          People

          • Assignee:
            scripting-issues
            Reporter:
            eprst
          • Votes:
            2 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: