Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.1.5, JRuby 1.1.6
-
Fix Version/s: JRuby 1.4
-
Component/s: Java Integration
-
Labels:None
-
Environment:Windows Vista and OS X 10.5.5 with JRuby 1.1.5 / 1.1.6RC1
-
Testcase included:yes
-
Number of attachments :
Description
I expect that when using BSF, the local scope will persist between eval calls until I call the bsfManager.terminate() method. The use case for this is an irb-like interface implemented in Java.
A test case LocalVariableTest is attached that demonstrates this issue. Up until JRuby 1.1.5, this worked, but starting with version JRuby 1.1.5 and in 1.1.6RC1 it has the following behavior:
1.1.6RC1
Failed to evaluate: puts x
Exception: (java):2: undefined local variable or method `x' for main:Object (NameError)
...internal jruby stack elided...
from (unknown).(unknown)(:1)
A patch for this issue was provided for 1.1.5 by Yoko Harada in this mailing list thread:
http://www.ruby-forum.com/topic/170058
Using that solution, I thought this issue could be resolved for 1.1.6RC1 by changing org.jruby.Ruby.jave line 223 from
Node node = parseEval(script, "<script>", newScope, 0);
to
Node node = parseEval(script, "<script>", newScope.getNextCapturedScope(), 0);
However, I tried this and it does not seem to work.
Can this be fixed for 1.1.6? If not, what are my options for supporting this use case? Should I be using JavaEmbedUtils?
Newly added parse methods in RubyRuntimeAdapter for http://jira.codehaus.org/browse/JRUBY-1489 haven't passed scope information. For the same reason, JSR223 JRuby engine fails to keep local scopes if it uses RubyRuntimeAdapter's parse methods. This patch resolves the problem. As far as I tested, it works well for both JSR 223 JRuby engine and BSF engine.