variables not visible when log4j jar is missing
-----------------------------------------------
Key: JRUBY-5305
URL: http://jira.codehaus.org/browse/JRUBY-5305
Project: JRuby
Issue Type: Bug
Components: Java Integration
Affects Versions: JRuby 1.5.5
Environment: Java 1.6, MacOSX 10.6.5
Reporter: Christoph Rueger
Priority: Minor
I discovered a strange phenomenon today where a ruby script stopped working
when log4j-1.2.14.jar was removed from the classpath.
This is the java code starting the scripting environment:
{code}
// Ruby code in a String
String script = requestObj.getCode(); // this is the ruby script..see
below
ScriptingContainer container = new
ScriptingContainer(LocalVariableBehavior.GLOBAL);
container.put("xml","<xml>some xml content...etc.</xml>")
EmbedEvalUnit parse = container.parse(script, 0);
IRubyObject run = parse.run();
String scriptResultString = container.callMethod(run, "getString",
String.class);
{code}
Here is the ruby code which is inside the *script* variable above:
{code}
def getString
puts "test" + $xml
end
{code}
Here is the situation:
The output until today was that the *getString* method was executed and the
output was:
{code}
<xml>some xml content...etc.</xml>
{code}
Today I discovered an unneeded log4j-1.2.14.jar in my classpath, which I wanted
to be removed (more to this later).
After I removed the log4j-1.2.14.jar from the classpath the code above suddenly
stopped working with the following stacktrace in the console:
{code}
<script>:4:in `getString': can't convert nil into String (TypeError)
from <script>:2
{code}
and the following stacktrace in the logfile:
{code}
org.jruby.embed.InvokeFailedException: can't convert nil into String
at
org.jruby.embed.internal.EmbedRubyObjectAdapterImpl.call(EmbedRubyObjectAdapterImpl.java:397)
at
org.jruby.embed.internal.EmbedRubyObjectAdapterImpl.callMethod(EmbedRubyObjectAdapterImpl.java:144)
at
org.jruby.embed.ScriptingContainer.callMethod(ScriptingContainer.java:1275)
at
com.synesty.myapplication.scripting.ruby.internal.JRubyExecutorImpl.executeStep(JRubyExecutorImpl.java:113)
...
Caused by: org.jruby.exceptions.RaiseException: can't convert nil into String
at (unknown).new(<script>:4)
at Object.getString(<script>:2)
at (unknown).(unknown)(:1)
{code}
*Why I want to remove the log4j jar?*
I am running a web-app in an OSGI environment using SLF4J for logging and the
accordant bridges so that I can capture the logging calls of the other
frameworks (Java.util (JUL) and apache.commons.logging (JCL)) and pipe it into
my slf4j implementation (i am using logback). In order to do that, all native
log4j and jcl implementations need to be removed from the classpath, as the
slf4j bridges are exposing the 'fake' jcl and log4j packages. anyway, that's
just for the background and that generally works.
But today I discovered that there is still a log4j jar in the classpath, and as
I wanted to clean this up to avoid possible side effects I removed it from the
classpath.
But this has introduced the problem described above that my ruby code stopped
working.
*Is there some exception swallowed somewhere which I don't see?*
I am puzzled. I don't see how the absence or presence of log4j jar should
affect the Scripting environment for jRuby in java. Is there maybe something I
haven't seen yet? Maybe some more logging output, which I am not capturing
right now or which is swallowed? Any hints what else I could do to debug?
*Is this reproducible?*
Yes. As soon as I put back the log4j jar the ruby code starts working again.
Other parts of my application seem to be unaffected by the absence of the log4j
jar.
Thanks for your help, and sorry if this was the wrong place for this kind of
problem.
Christoph
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email