JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-3113

First script engine call can incorrectly report error as in a builtin, subsequent identical calls do not

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.1.5
    • Fix Version/s: None
    • Component/s: Intro, Java Integration
    • Labels:
      None
    • Environment:
      Linux clevo 2.6.25.14-69.fc8 #1 SMP Mon Aug 4 14:20:24 EDT 2008 i686 i686 i386 GNU/Linux
    • Number of attachments :
      1

      Description

      from #jruby:
      CaneToad: it seems the first time you invoke the script engine, it can report the error to be in the builtins when it isn't...doesn't happens on subsequent calls to the script engine
      headius: hmmm
      ...
      headius: I'd say go ahead and file it

      Java code to reproduce:
      ////////////////////////////////////////////////////////////////////

      import javax.script.*;
      public class jruby2 {
        public static void run(ScriptEngine engine, String msg) {
          System.err.println(msg);
          try {
            engine.eval("a=Hello");
          } catch(ScriptException e) {
            e.getCause().printStackTrace(System.err);
          }
        }
        public static void main(String [] args) throws Exception {
          ScriptEngineManager manager = new ScriptEngineManager(); 
          ScriptEngine engine = manager.getEngineByName("jruby");
          run(engine, "------------ first");
          run(engine, "------------ second");
        }
      }
      

      ////////////////////////////////////////////////////////////////////

      Here's what it gives:

      [dcampbel@clevo ~]$ javac -classpath .:jruby.jar:jruby-engine.jar jruby2.java
      [dcampbel@clevo ~]$ java -classpath .:jruby.jar:jruby-engine.jar jruby2
      ------------ first
      /builtin/javasupport.rb:49:in `const_missing': uninitialized constant Hello (NameError)
              from <unknown>:1
              ...internal jruby stack elided...
              from Module.const_missing(<unknown>:1)
              from (unknown).(unknown)(:1)
      ------------ second
      null:1:in `const_missing': uninitialized constant Hello (NameError)
              from <unknown>:1
              ...internal jruby stack elided...
              from Module.const_missing(<unknown>:1)
              from (unknown).(unknown)(:1)
      

      Notice that the first call reports the error in a builtin, while the second identical call does not

        Activity

        Charles Oliver Nutter made changes -
        Field Original Value New Value
        Description from #jruby:
        CaneToad: it seems the first time you invoke the script engine, it can report the error to be in the builtins when it isn't...doesn't happens on subsequent calls to the script engine
        headius: hmmm
        ...
        headius: I'd say go ahead and file it

        Java code to reproduce:
        ////////////////////////////////////////////////////////////////////

        import javax.script.*;
        public class jruby2 {
          public static void run(ScriptEngine engine, String msg) {
            System.err.println(msg);
            try {
              engine.eval("a=Hello");
            } catch(ScriptException e) {
              e.getCause().printStackTrace(System.err);
            }
          }
          public static void main(String [] args) throws Exception {
            ScriptEngineManager manager = new ScriptEngineManager();
            ScriptEngine engine = manager.getEngineByName("jruby");
            run(engine, "------------ first");
            run(engine, "------------ second");
          }
        }

        ////////////////////////////////////////////////////////////////////

        Here's what it gives:

        [dcampbel@clevo ~]$ javac -classpath .:jruby.jar:jruby-engine.jar jruby2.java
        [dcampbel@clevo ~]$ java -classpath .:jruby.jar:jruby-engine.jar jruby2
        ------------ first
        /builtin/javasupport.rb:49:in `const_missing': uninitialized constant Hello (NameError)
                from <unknown>:1
                ...internal jruby stack elided...
                from Module.const_missing(<unknown>:1)
                from (unknown).(unknown)(:1)
        ------------ second
        null:1:in `const_missing': uninitialized constant Hello (NameError)
                from <unknown>:1
                ...internal jruby stack elided...
                from Module.const_missing(<unknown>:1)
                from (unknown).(unknown)(:1)


        Notice that the first call reports the error in a builtin, while the second identical call does not
        from #jruby:
        CaneToad: it seems the first time you invoke the script engine, it can report the error to be in the builtins when it isn't...doesn't happens on subsequent calls to the script engine
        headius: hmmm
        ...
        headius: I'd say go ahead and file it

        Java code to reproduce:
        ////////////////////////////////////////////////////////////////////

        {noformat}
        import javax.script.*;
        public class jruby2 {
          public static void run(ScriptEngine engine, String msg) {
            System.err.println(msg);
            try {
              engine.eval("a=Hello");
            } catch(ScriptException e) {
              e.getCause().printStackTrace(System.err);
            }
          }
          public static void main(String [] args) throws Exception {
            ScriptEngineManager manager = new ScriptEngineManager();
            ScriptEngine engine = manager.getEngineByName("jruby");
            run(engine, "------------ first");
            run(engine, "------------ second");
          }
        }
        {noformat}

        ////////////////////////////////////////////////////////////////////

        Here's what it gives:

        {noformat}
        [dcampbel@clevo ~]$ javac -classpath .:jruby.jar:jruby-engine.jar jruby2.java
        [dcampbel@clevo ~]$ java -classpath .:jruby.jar:jruby-engine.jar jruby2
        ------------ first
        /builtin/javasupport.rb:49:in `const_missing': uninitialized constant Hello (NameError)
                from <unknown>:1
                ...internal jruby stack elided...
                from Module.const_missing(<unknown>:1)
                from (unknown).(unknown)(:1)
        ------------ second
        null:1:in `const_missing': uninitialized constant Hello (NameError)
                from <unknown>:1
                ...internal jruby stack elided...
                from Module.const_missing(<unknown>:1)
                from (unknown).(unknown)(:1)
        {noformat}

        Notice that the first call reports the error in a builtin, while the second identical call does not
        Hide
        Charles Oliver Nutter added a comment -

        This may be simply a side-effect of Java integration lazily initializing. The first call triggers JI stuff to load up, which insinuates itself into the stack trace. The second call already has JI initialized, so it doesn't show up. I suspect requiring 'java' before the first call would cause both traces to be the same. Pretty minor issue though, and I'm not sure whether we can or need to fix it.

        Show
        Charles Oliver Nutter added a comment - This may be simply a side-effect of Java integration lazily initializing. The first call triggers JI stuff to load up, which insinuates itself into the stack trace. The second call already has JI initialized, so it doesn't show up. I suspect requiring 'java' before the first call would cause both traces to be the same. Pretty minor issue though, and I'm not sure whether we can or need to fix it.
        Hide
        Charles Oliver Nutter added a comment -

        This may no longer be an issue with our new ScriptEngine provided by Yoko Harada, or it could be fixed easily by having the engine logic require all files necessary on construction rather than on first execution.

        Show
        Charles Oliver Nutter added a comment - This may no longer be an issue with our new ScriptEngine provided by Yoko Harada, or it could be fixed easily by having the engine logic require all files necessary on construction rather than on first execution.
        Charles Oliver Nutter made changes -
        Component/s Intro [ 14308 ]
        Hide
        Yoko Harada added a comment -

        Unfortunately, this happens even on JRuby Embed based JSR223 implementation, too.

        I'm guessing that calling Ruby#tearDown() at the end of every evaluation causes this. While tearing down the local thread context or some other stuff, the information, "/builtin/javasupport.rb:49," might be lost. Probably, Ruby runtime gets the info from parser, but clears it up in tearDown() method.

        Show
        Yoko Harada added a comment - Unfortunately, this happens even on JRuby Embed based JSR223 implementation, too. I'm guessing that calling Ruby#tearDown() at the end of every evaluation causes this. While tearing down the local thread context or some other stuff, the information, "/builtin/javasupport.rb:49," might be lost. Probably, Ruby runtime gets the info from parser, but clears it up in tearDown() method.
        Hide
        Yoko Harada added a comment -

        I figured out why file info has been lost for the second eval. As I guessed, calling Ruby#tearDown() caused the problem, precisely, getThreadService().disposeCurrentThread(). When this method is called, localCcontext.set(null) sets null to mainContext. This is why filename info disappears in the second eval since such info is saved in mainContext.

        Attached file resolves the bug. Maybe, simply deleting the line of localContext.set(null); would work since disposeCurrentThread() method is called only from tearDown(), which is used multiple times perhaps only by embedding API or embedders.

        Show
        Yoko Harada added a comment - I figured out why file info has been lost for the second eval. As I guessed, calling Ruby#tearDown() caused the problem, precisely, getThreadService().disposeCurrentThread(). When this method is called, localCcontext.set(null) sets null to mainContext. This is why filename info disappears in the second eval since such info is saved in mainContext. Attached file resolves the bug. Maybe, simply deleting the line of localContext.set(null); would work since disposeCurrentThread() method is called only from tearDown(), which is used multiple times perhaps only by embedding API or embedders.
        Yoko Harada made changes -
        Attachment ThreadService.patch [ 46788 ]
        Hide
        Yoko Harada added a comment -

        This issue should be resolved with JRUBY-4589. The reason of awkward error message produced in the second time eval was calling Ruby.tearDown() in every evaluation. Since commit 673df9f, tearDown() won't be executed explicitly. As far as I tested, error message of the second eval was the same as the first one. I think nothing was lost.

         
        ------------ first
        /builtin/core_ext/symbol.rb:1:in `const_missing': uninitialized constant Hello (NameError)
        	from <script>:1
        org.jruby.embed.EvalFailedException: uninitialized constant Hello
        	at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:126)
        	at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:152)
        	at redbridge.jruby2.run(jruby2.java:22)
        	at redbridge.jruby2.main(jruby2.java:31)
        Caused by: org.jruby.exceptions.RaiseException: uninitialized constant Hello
        	at (unknown).(unknown)(/builtin/core_ext/symbol.rb:1)
        	at Module.const_missing(<script>:1)
        	at (unknown).(unknown)(:1)
        /builtin/core_ext/symbol.rb:1:in `const_missing': uninitialized constant Hello (NameError)
        	from <script>:1
        	...internal jruby stack elided...
        	from Module.const_missing(<script>:1)
        	from (unknown).(unknown)(:1)
        ------------ second
        /builtin/core_ext/symbol.rb:1:in `const_missing': uninitialized constant Hello (NameError)
        	from <script>:1
        org.jruby.embed.EvalFailedException: uninitialized constant Hello
        	at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:126)
        	at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:152)
        	at redbridge.jruby2.run(jruby2.java:22)
        	at redbridge.jruby2.main(jruby2.java:32)
        Caused by: org.jruby.exceptions.RaiseException: uninitialized constant Hello
        	at (unknown).(unknown)(/builtin/core_ext/symbol.rb:1)
        	at Module.const_missing(<script>:1)
        	at (unknown).(unknown)(:1)
        /builtin/core_ext/symbol.rb:1:in `const_missing': uninitialized constant Hello (NameError)
        	from <script>:1
        	...internal jruby stack elided...
        	from Module.const_missing(<script>:1)
        	from (unknown).(unknown)(:1)
        

        Perhaps, this would be a reasonable fix.

        Show
        Yoko Harada added a comment - This issue should be resolved with JRUBY-4589 . The reason of awkward error message produced in the second time eval was calling Ruby.tearDown() in every evaluation. Since commit 673df9f, tearDown() won't be executed explicitly. As far as I tested, error message of the second eval was the same as the first one. I think nothing was lost. ------------ first /builtin/core_ext/symbol.rb:1:in `const_missing': uninitialized constant Hello (NameError) from <script>:1 org.jruby.embed.EvalFailedException: uninitialized constant Hello at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:126) at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:152) at redbridge.jruby2.run(jruby2.java:22) at redbridge.jruby2.main(jruby2.java:31) Caused by: org.jruby.exceptions.RaiseException: uninitialized constant Hello at (unknown).(unknown)(/builtin/core_ext/symbol.rb:1) at Module.const_missing(<script>:1) at (unknown).(unknown)(:1) /builtin/core_ext/symbol.rb:1:in `const_missing': uninitialized constant Hello (NameError) from <script>:1 ...internal jruby stack elided... from Module.const_missing(<script>:1) from (unknown).(unknown)(:1) ------------ second /builtin/core_ext/symbol.rb:1:in `const_missing': uninitialized constant Hello (NameError) from <script>:1 org.jruby.embed.EvalFailedException: uninitialized constant Hello at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:126) at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:152) at redbridge.jruby2.run(jruby2.java:22) at redbridge.jruby2.main(jruby2.java:32) Caused by: org.jruby.exceptions.RaiseException: uninitialized constant Hello at (unknown).(unknown)(/builtin/core_ext/symbol.rb:1) at Module.const_missing(<script>:1) at (unknown).(unknown)(:1) /builtin/core_ext/symbol.rb:1:in `const_missing': uninitialized constant Hello (NameError) from <script>:1 ...internal jruby stack elided... from Module.const_missing(<script>:1) from (unknown).(unknown)(:1) Perhaps, this would be a reasonable fix.
        Charles Oliver Nutter made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Charles Oliver Nutter [ headius ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            David Campbell
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: