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

LoadError when loading a class with inline hash using instance vars as values. #5341

Closed
mfinnessy opened this Issue Oct 2, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@mfinnessy
Copy link

mfinnessy commented Oct 2, 2018

Environment

Same result experienced on Mac and Alpine Linux

  • JRuby version (jruby -v) and command line (flags, JRUBY_OPTS, etc)

Alpine:

jruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 OpenJDK 64-Bit Server VM 25.171-b11 on 1.8.0_171-b11 +jit [linux-x86_64]
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (IcedTea 3.8.0) (Alpine 8.171.11-r0)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)

MacOS:

jruby 9.2.0.0 (2.5.0) 2018-05-24 81156a8 Java HotSpot(TM) 64-Bit Server VM 25.77-b03 on 1.8.0_77-b03 +jit [darwin-x86_64]
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)
Darwin MacBook-Pro.local 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64 x86_64

Expected Behavior

Given the following script:

class MyClass
  attr_accessor :a
  attr_accessor :b

  def doit()
    {:a => 'a', :b => 'b'}
  end
end

I expect jruby to load both the rb file and class:

MacBook-Pro:tmp$ java -classpath "/Users/x/.rvm/gems/jruby-9.2.0.0/gems/jruby-jars-9.2.0.0/lib/jruby-core-9.2.0.0-complete.jar":"/Users/x/.rvm/gems/jruby-9.2.0.0/gems/jruby-jars-9.2.0.0/lib/jruby-stdlib-9.2.0.0.jar":"/Users/x/.rvm/gems/jruby-9.2.0.0/gems/jruby-rack-1.1.21/lib/jruby-rack-1.1.21.jar"  org.jruby.Main -S jrubyc  "my_class.rb"
MacBook-Pro:tmp$ ruby -e "load 'my_class.rb'"
MacBook-Pro:tmp$ ruby -e "load 'my_class.class'"
MacBook-Pro:tmp$ 

Actual Behavior

However, when I change the function to return the instance vars:

class MyClass
  attr_accessor :a
  attr_accessor :b

  def doit()
    {:a => @a, :b => @b}
  end
end

the class does not load properly

MacBook-Pro:tmp$ java -classpath "/Users/x/.rvm/gems/jruby-9.2.0.0/gems/jruby-jars-9.2.0.0/lib/jruby-core-9.2.0.0-complete.jar":"/Users/x/.rvm/gems/jruby-9.2.0.0/gems/jruby-jars-9.2.0.0/lib/jruby-stdlib-9.2.0.0.jar":"/Users/x/.rvm/gems/jruby-9.2.0.0/gems/jruby-rack-1.1.21/lib/jruby-rack-1.1.21.jar"  org.jruby.Main -S jrubyc  "my_class.rb"
MacBook-Pro:tmp$ ruby -e "load 'my_class.rb'"
MacBook-Pro:tmp$ ruby -e "load 'my_class.class'"
LoadError: my_class.class is not compiled Ruby; use java_import to load normal classes
    load at org/jruby/RubyKernel.java:994
  <main> at -e:1
MacBook-Pro:tmp$ 

Additionally, attempting to load the class with java results in a null pointer exception (this works fine with the first, working example using string literals as values):

MacBook-Pro:tmp$ java -cp ".:/Users/x/.rvm/gems/jruby-9.2.0.0/gems/jruby-jars-9.2.0.0/lib/jruby-core-9.2.0.0-complete.jar":"/Users/x/.rvm/gems/jruby-9.2.0.0/gems/jruby-jars-9.2.0.0/lib/jruby-stdlib-9.2.0.0.jar":"/Users/x/.rvm/gems/jruby-9.2.0.0/gems/jruby-rack-1.1.21/lib/jruby-rack-1.1.21.jar" my_class
Exception in thread "main" java.lang.NullPointerException
	at org.jruby.ir.persistence.IRReaderStream.decodeEncoding(IRReaderStream.java:107)
	at org.jruby.ir.persistence.IRReaderStream.decodeByteList(IRReaderStream.java:93)
	at org.jruby.ir.persistence.IRReaderStream.decodeSymbol(IRReaderStream.java:133)
	at org.jruby.ir.instructions.GetFieldInstr.decode(GetFieldInstr.java:36)
	at org.jruby.ir.persistence.IRReaderStream.decodeInstr(IRReaderStream.java:263)
	at org.jruby.ir.persistence.IRReaderStream.decodeInstructionsAt(IRReaderStream.java:201)
	at org.jruby.ir.persistence.IRReader$1.call(IRReader.java:62)
	at org.jruby.ir.persistence.IRReader$1.call(IRReader.java:60)
	at org.jruby.ir.interpreter.InterpreterContext.getEngine(InterpreterContext.java:48)
	at org.jruby.ir.interpreter.InterpreterContext.getInstructions(InterpreterContext.java:180)
	at org.jruby.ir.interpreter.InterpreterContext.computeScopeFlagsFromInstructions(InterpreterContext.java:186)
	at org.jruby.ir.IRScope.computeScopeFlags(IRScope.java:772)
	at org.jruby.ir.persistence.IRReader.load(IRReader.java:71)
	at org.jruby.ir.runtime.IRRuntimeHelpers.decodeScopeFromBytes(IRRuntimeHelpers.java:1681)
	at my_class.main(my_class.rb)

I am able to execute this code using rspec and get appropriate results. This only affects the compiled java class. Not sure if there is anything needed from Warbler, but I am also using Warbler 2.0.5 to build the jar file. As shown above, the issue is clearly upstream from warbler, although I see the exact same behavior from the jar file.

@mfinnessy

This comment has been minimized.

Copy link
Author

mfinnessy commented Oct 2, 2018

More context. Rolling local JRuby install back to 9.1.17.0 and locking the jrubys-jars gem at 9.1.17.0 resolved the issue. Looks like it's localized to 9.2.0.0.

@headius

This comment has been minimized.

Copy link
Member

headius commented Oct 9, 2018

Both of the cases you point out appear to work correctly on JRuby master, which may mean they're already fixed for 9.2.1. Can you test out a snapshot build and let us know if you still see the problem?

https://projectodd.ci.cloudbees.com/view/JRuby/job/jruby-development-dist/lastSuccessfulBuild/artifact/release/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.