Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constant becomes nil when running ScriptEngine with transient/persistent local variables. #4720

Closed
dmac100 opened this issue Jul 19, 2017 · 1 comment
Milestone

Comments

@dmac100
Copy link

dmac100 commented Jul 19, 2017

Environment

jruby-complete-9.1.6.0.jar and current master
Windows 7 and Linux
Java 1.8.0_131 Oracle JDK 64 bit

Expected Behavior

With:

System.setProperty("org.jruby.embed.localvariable.behavior", "transient");
// or System.setProperty("org.jruby.embed.localvariable.behavior", "persistent");

ScriptEngine engine = new ScriptEngineManager().getEngineByName("jruby");
engine.eval("require 'date'");
engine.eval("Date.new");
engine.eval("require 'date'");
engine.eval("Date.new");

this should produce nothing.

Actual Behavior

Throws exception:

NoMethodError: undefined method `>' for nil:NilClass
   civil at uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/date.rb:829
  <main> at <script>:1
Exception in thread "main" javax.script.ScriptException: org.jruby.embed.EvalFailedException: (NoMethodError) undefined method `>' for nil:NilClass
    at org.jruby.embed.jsr223.JRubyEngine.wrapException(JRubyEngine.java:104)
    at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:93)
    at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:142)
    at Main.main(Main.java:13)
Caused by: org.jruby.embed.EvalFailedException: (NoMethodError) undefined method `>' for nil:NilClass
    at org.jruby.embed.internal.EmbedEvalUnitImpl.run(EmbedEvalUnitImpl.java:131)
    at org.jruby.embed.jsr223.JRubyEngine.eval(JRubyEngine.java:90)
    ... 2 more
Caused by: org.jruby.exceptions.RaiseException: (NoMethodError) undefined method `>' for nil:NilClass
    at RUBY.civil(uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/date.rb:829)
    at RUBY.<main>(<script>:1)

Replacing date.rb with:

class Date
    ABC = 2

    def initialize
        puts "ABC: #{ABC.nil?}"
    end
end

Shows that the constant ABC becomes nil the second time Date.new is run. This is fine if the constant is named 'A' though.

@kares
Copy link
Member

kares commented Jun 12, 2018

confirmed that this is working in 9.2.0, please note that 9.2 switched local variable behavior to PERSISTENT

@kares kares closed this as completed Jun 12, 2018
@kares kares added this to the JRuby 9.2.0.0 milestone Jun 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants