Details
Description
Calling the BSF interface apply with a non-empty Vector of names and objects results in an IndexOutOfBoundsException:
BSFManager m = new BSFManager();
Vector<String> names = new Vector<String>();
Vector<Object> objects = new Vector<Object>();
names.add("activity");
objects.add(new Integer(1));
m.apply("ruby", "(java)", 1,1, "puts \"Hello, world: #
\" ", names, objects );
Exception in thread "main" 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.javasupport.bsf.JRubyEngine.apply(JRubyEngine.java:78)
at org.apache.bsf.BSFManager$1.run(BSFManager.java:215)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.bsf.BSFManager.apply(BSFManager.java:212)
at de.lerncultur.script.TestRuby.main(TestRuby.java:25)
As far as I can see, the ManyVarsDynamic scope gets created too early in this case. It inherits a variable count of "0" from its enclosing static scope. Later, the variable names are set in the static scope, but that does not result in a recreationg of the dynamic scope. That's why the actual value assignment fails.
Sounds like the apply implementation for our BSF engine should be forcing the scope to recalculate size if necessary. Maybe you can dig up where that happens and provide a patch?