JRuby 1.4 embedding, '$!' global exception variable - possible RedBridge bug?

I’m getting some very strange behavior requiring the standard Ruby cgi
library running embedded in a Java program using RedBridge with JRuby
1.4.0.
This Java program will reproduce the problem:

import org.jruby.embed.ScriptingContainer;

public class EmbedTest {
public static void main(String[] args) {
ScriptingContainer container = new ScriptingContainer();
container.runScriptlet(“require ‘cgi’”);
container.runScriptlet(“require ‘hello’”);
}
}

‘hello.rb’ is an empty file in my classpath.

When run I get the following:

~% java EmbedTest

:1 warning: warning: variable $= is no longer effective :1: $! not set. (ArgumentError) Exception in thread "main" org.jruby.embed.EvalFailedException: $! not set. at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:116) at org.jruby.embed.ScriptingContainer.runUnit(ScriptingContainer.java:457) at org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:450) at EmbedTest.main(EmbedTest.java:8) Caused by: org.jruby.exceptions.RaiseException: $! not set. at (unknown).new(:1) at (unknown).(unknown)(:1) If I get rid of the line requiring hello.rb I just get the first warning message about $= not being effective. So far only the 'cgi' require causes the problem. For example "require 'date'" doesn't cause any problems. From the command line I can do: jruby -e "require 'cgi'; require 'hello'" and it works just fine. It's only when I embed, and only when I make separate calls to runScriptlet that causes the problem. I tried LocalContext.SINGLETON, THREADSAFE and SINGLETHREAD all with the same results. Could this be a JRUby emebed / Redbridge bug of some sort? (This is a problem for me because I'm trying to embed a ruby program that uses ActiveRecord, which depends on ActiveSupport, which in turn requires 'cgi'. I can run my program from the command line using JRuby 1.4.0 just fine, but I can't embed it; I get the above error.) Steve

Hi Steve,

On Tue, Nov 10, 2009 at 7:08 PM, Steve M. [email protected]
wrote:

}
org.jruby.embed.ScriptingContainer.runScriptlet(ScriptingContainer.java:450)
separate calls to runScriptlet that causes the problem. I tried
LocalContext.SINGLETON, THREADSAFE and SINGLETHREAD all with the same
results.
Could this be a JRUby emebed / Redbridge bug of some sort?

I think this is a bug. It probably comes from sharing variables of Red
Bridge. Current implementation is too greedy and grabs too much
variables. The grabbed variables are used to inject into scripts for
next evaluation.
Would you file this in jira?

-Yoko

(This is a problem for me because I’m trying to embed a ruby program that
uses ActiveRecord, which depends on ActiveSupport, which in turn requires
‘cgi’. I can run my program from the command line using JRuby 1.4.0 just
fine, but I can’t embed it; I get the above error.)
Steve


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email