Skip to content

Changing type of global variables gives TypeError #4178

@dmac100

Description

@dmac100

Environment

jruby-complete-9.1.5.0.jar
Java 1.8.0_25
Linux x86_64

Expected Behavior

With:

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

public class Main {
    public static void main(String[] args) throws Exception {
        System.setProperty("jruby.backtrace.style", "full");
        ScriptEngine engine = new ScriptEngineManager().getEngineByName("jruby");
        System.out.println(engine.eval("$x = 10"));
        System.out.println(engine.eval("$x = 'a'"));
    }
}

The output should be '10' followed by 'a'.

Actual Behavior

I'm getting '10', followed by:


Exception in thread "main" org.jruby.exceptions.RaiseException: (TypeError) cannot convert instance of class org.jruby.RubyString to class java.lang.Long
    at java.lang.Thread.getStackTrace(java/lang/Thread.java:1552)
    at org.jruby.runtime.backtrace.TraceType$Gather.getBacktraceData(org/jruby/runtime/backtrace/TraceType.java:246)
    at org.jruby.runtime.backtrace.TraceType.getBacktrace(org/jruby/runtime/backtrace/TraceType.java:47)
    at org.jruby.RubyException.prepareBacktrace(org/jruby/RubyException.java:235)
    at org.jruby.exceptions.RaiseException.preRaise(org/jruby/exceptions/RaiseException.java:214)
    at org.jruby.exceptions.RaiseException.preRaise(org/jruby/exceptions/RaiseException.java:181)
    at org.jruby.exceptions.RaiseException.<init>(org/jruby/exceptions/RaiseException.java:111)
    at org.jruby.Ruby.newRaiseException(org/jruby/Ruby.java:4192)
    at org.jruby.Ruby.newTypeError(org/jruby/Ruby.java:3865)
    at org.jruby.RubyBasicObject.defaultToJava(org/jruby/RubyBasicObject.java:872)
    at org.jruby.RubyBasicObject.toJava(org/jruby/RubyBasicObject.java:843)
    at org.jruby.RubyString.toJava(org/jruby/RubyString.java:5541)
    at org.jruby.embed.variable.AbstractVariable.getJavaObject(org/jruby/embed/variable/AbstractVariable.java:140)
    at org.jruby.embed.variable.GlobalVariable.getJavaObject(org/jruby/embed/variable/GlobalVariable.java:46)
    at org.jruby.embed.internal.BiVariableMap.get(org/jruby/embed/internal/BiVariableMap.java:229)
    at org.jruby.embed.internal.BiVariableMap.get(org/jruby/embed/internal/BiVariableMap.java:208)
    at org.jruby.embed.jsr223.Utils.postEval(org/jruby/embed/jsr223/Utils.java:207)
    at org.jruby.embed.jsr223.JRubyEngine.eval(org/jruby/embed/jsr223/JRubyEngine.java:95)
    at org.jruby.embed.jsr223.JRubyEngine.eval(org/jruby/embed/jsr223/JRubyEngine.java:142)
    at Main.main(Main.java:10)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions