Skip to content

Commit

Permalink
Uncache previously-used Java type when assigning a bare value.
Browse files Browse the repository at this point in the history
Fixes #4178.
  • Loading branch information
headius committed Sep 27, 2016
1 parent 21b9760 commit 8347545
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Expand Up @@ -102,7 +102,8 @@ protected void updateByJavaObject(final Ruby runtime, Object... values) {
} else if (values.length > 1) {
javaType = (Class) values[1];
} else {
javaType = javaObject.getClass();
// When a new object comes in without a target type, clear out cached type
javaType = null;
}
irubyObject = JavaEmbedUtils.javaToRuby(runtime, javaObject);
fromRuby = false;
Expand Down Expand Up @@ -141,9 +142,6 @@ public Object getJavaObject() {
}
else { // Ruby originated variables
javaObject = irubyObject.toJava(Object.class);
if (javaObject != null) {
javaType = javaObject.getClass();
}
}
return javaObject;
}
Expand Down
@@ -0,0 +1,9 @@
describe "java.script.ScriptManager for JRuby" do
describe "when assigning global variables" do
it "allows different types of values to be assigned in sequence" do
engine = javax.script.ScriptEngineManager.new.getEngineByName("jruby")
expect(engine.eval("$x = 10")).to eq 10
expect(engine.eval("$x = 'a'")).to eq 'a'
end
end
end

0 comments on commit 8347545

Please sign in to comment.