jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • JRuby
  • JRUBY-3113

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

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • 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

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

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Text File
    ThreadService.patch
    06/Jan/10 12:12 PM
    0.6 kB
    Yoko Harada

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Charles Oliver Nutter added a comment - 12/Feb/09 3:20 AM

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 - 12/Feb/09 3:20 AM 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
Permalink
Charles Oliver Nutter added a comment - 05/Jan/10 3:36 PM

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 - 05/Jan/10 3:36 PM 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.
Hide
Permalink
Yoko Harada added a comment - 05/Jan/10 5:24 PM

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 - 05/Jan/10 5:24 PM 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
Permalink
Yoko Harada added a comment - 06/Jan/10 12:12 PM

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 - 06/Jan/10 12:12 PM 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.
Hide
Permalink
Yoko Harada added a comment - 25/Feb/10 2:54 PM

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 - 25/Feb/10 2:54 PM 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.

People

  • Assignee:
    Unassigned
    Reporter:
    David Campbell
Vote (0)
Watch (1)

Dates

  • Created:
    05/Nov/08 8:32 PM
    Updated:
    25/Feb/10 2:54 PM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.