Search code examples
javajava-8rhinoretrotranslator

Working Rhino code with Java 1.7 and make Exeception with Java 1.8


My application use Rhino to mix javascript code and Java objects.

Every things work great with JVM 1.5, 1.6 and 1.7, but generate a bad ArrayIndexOutOfBoundsException when using JVM 1.8.0 at runtime:

import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;

public class RhinoOn8 {

    static public void main(String[] args) throws SecurityException, NoSuchMethodException {        
        Context ctx = Context.enter();
        Scriptable scope = ctx.initStandardObjects();
        Object ev = ctx.evaluateString(scope, "'' + java.lang.System.getProperty(\"user.name\")", "exec", 0, null);
        System.out.println(ev);
        Context.exit();
    }
}

Run fine on JVM Oracle 1.7.0_55 and do this on JVM Oracle 1.8.0_31 :

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5747
    at org.mozilla.javascript.net.sf.retrotranslator.runtime.asm.ClassReader.readClass(ClassReader.java:1572)
    at org.mozilla.javascript.net.sf.retrotranslator.runtime.asm.ClassReader.accept(ClassReader.java:341)
    at org.mozilla.javascript.net.sf.retrotranslator.runtime.asm.ClassReader.accept(ClassReader.java:300)
    at org.mozilla.javascript.net.sf.retrotranslator.runtime.impl.ClassDescriptor.<init>(ClassDescriptor.java:67)
    at org.mozilla.javascript.net.sf.retrotranslator.runtime.impl.ClassDescriptor.getInstance(ClassDescriptor.java:82)
    at org.mozilla.javascript.net.sf.retrotranslator.runtime.impl.MethodDescriptor.getInstance(MethodDescriptor.java:120)
    at org.mozilla.javascript.net.sf.retrotranslator.runtime.java.lang.reflect._Method.isVarArgs(_Method.java:96)
    at org.mozilla.javascript.jdk15.VMBridge_jdk15.isVarArgs(VMBridge_jdk15.java:33)
    at org.mozilla.javascript.MemberBox.init(MemberBox.java:44)
    at org.mozilla.javascript.MemberBox.<init>(MemberBox.java:32)
    at org.mozilla.javascript.JavaMembers.reflect(JavaMembers.java:455)
    at org.mozilla.javascript.JavaMembers.<init>(JavaMembers.java:43)
    at org.mozilla.javascript.JavaMembers.lookupClass(JavaMembers.java:807)
    at org.mozilla.javascript.NativeJavaObject.initMembers(NativeJavaObject.java:54)
    at org.mozilla.javascript.NativeJavaObject.<init>(NativeJavaObject.java:44)
    at org.mozilla.javascript.NativeJavaObject.<init>(NativeJavaObject.java:34)
    at org.mozilla.javascript.WrapFactory.wrapAsJavaObject(WrapFactory.java:115)
    at org.mozilla.javascript.WrapFactory.wrap(WrapFactory.java:72)
    at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:236)
    at org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:32)
    at org.mozilla.javascript.gen.exec_1._c_script_0(exec:0)
    at org.mozilla.javascript.gen.exec_1.call(exec)
    at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:394)
    at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3091)
    at org.mozilla.javascript.gen.exec_1.call(exec)
    at org.mozilla.javascript.gen.exec_1.exec(exec)
    at org.mozilla.javascript.Context.evaluateString(Context.java:1079)
    at RhinoOn8.main(RhinoOn8.java:12)

I tried with Rhino1.7R4 and Rhino1.7R5pre with the same result.

Someone knows a workaround (wihtout changing JS sources) ?


Solution

  • Use the js.jar, not the js-14.jar needed by the JVM 1.4.