Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Critical
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.6RC2
-
Fix Version/s: JRuby 1.6.6
-
Component/s: Embedding
-
Labels:None
-
Environment:WindowsXP, JavaSDK 1.6.0_07; The bug also occurs with JRuby 1.5.0 and 1.5.6
-
Number of attachments :
Description
If you use ScriptContext.setAttribute() in combination with compiled JRuby script then JRuby throws an exception:
java.lang.ArrayIndexOutOfBoundsException: 0
at org.jruby.runtime.scope.ManyVarsDynamicScope.setValueDepthZero(ManyVarsDynamicScope.java:158)
at org.jruby.runtime.scope.ManyVarsDynamicScope.setValue(ManyVarsDynamicScope.java:151)
at org.jruby.embed.variable.VariableInterceptor.inject(VariableInterceptor.java:128)
at org.jruby.embed.internal.BiVariableMap.inject(BiVariableMap.java:381)
at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:111)
at org.jruby.embed.jsr223.JRubyCompiledScript.eval(JRubyCompiledScript.java:87)
at at.alphagate.mesgateway.NewMain.<init>(NewMain.java:100)
Test Code:
System.setProperty("org.jruby.embed.localcontext.scope", "threadsafe");
System.setProperty("org.jruby.embed.localvariable.behavior", "transient");
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine rbEngine = manager.getEngineByName("jruby");
ScriptContext context = new SimpleScriptContext();
String[] texts = new String[]
;
context.setAttribute("texts", texts, ScriptContext.ENGINE_SCOPE);
String rbScript =
" require 'java'\n" +
" puts 'test script'\n" +
" puts texts[0]\n";
rbEngine.eval(rbScript, context); // is OK
CompiledScript compiledScript = ((Compilable) rbEngine).compile(rbScript);
compiledScript.eval(context); // throws exception
Thanks for reporting the bug and helpful code. I could reproduce the exception. I'll have a look.