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

Autoload of module broken for Ruby subclass of Java class #3669

Closed
donv opened this issue Feb 15, 2016 · 6 comments
Closed

Autoload of module broken for Ruby subclass of Java class #3669

donv opened this issue Feb 15, 2016 · 6 comments

Comments

@donv
Copy link
Member

donv commented Feb 15, 2016

This is biting us in production.

Upgraded an app from JRuby 9.0.1.0 to 9.0.5.0, but the regression is present already in 9.0.2.0.

Given the following files, we get the output below:

test_autoload.rb:

require 'active_support/dependencies'
ActiveSupport::Dependencies.autoload_paths << File.expand_path(File.dirname(__FILE__))
ClassA.new
puts 'Success!'

class_a.rb:

class ClassA
  def initialize
    ClassB.new
  end
end

class_b.rb:

java_import 'JavaClass'

class ClassB < JavaClass
  include ModuleC
end

JavaClass.java:

public class JavaClass {
    public JavaClass() {
    }
}

module_c.rb:

module ModuleC
end

Compile the Java class with

javac JavaClass.java

Run with

rvm use jruby-9.0.1.0 && jruby test_autoload.rb

Output

Using /Users/uwe/.rvm/gems/jruby-9.0.1.0
Success!

With 9.0.2.0:

rvm use jruby-9.0.2.0 && jruby test_autoload.rb

Output

Using /Users/uwe/.rvm/gems/jruby-9.0.2.0
NameError: uninitialized constant ClassB::ModuleC
         <class:ClassB> at /Users/uwe/workspace/aifudis/operator/issue_autoload/class_b.rb:4
                  <top> at /Users/uwe/workspace/aifudis/operator/issue_autoload/class_b.rb:3
                   load at org/jruby/RubyKernel.java:955
        block in (root) at /Users/uwe/.rvm/gems/jruby-9.0.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:1
              load_file at /Users/uwe/.rvm/gems/jruby-9.0.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:457
       new_constants_in at /Users/uwe/.rvm/gems/jruby-9.0.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:647
              load_file at /Users/uwe/.rvm/gems/jruby-9.0.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:456
        require_or_load at /Users/uwe/.rvm/gems/jruby-9.0.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:354
  load_missing_constant at /Users/uwe/.rvm/gems/jruby-9.0.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:494
          const_missing at /Users/uwe/.rvm/gems/jruby-9.0.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:184
  load_missing_constant at /Users/uwe/.rvm/gems/jruby-9.0.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:526
          const_missing at /Users/uwe/.rvm/gems/jruby-9.0.2.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:184
                  <top> at test_autoload.rb:3

And with 9.0.5.0:

rvm use jruby-9.0.5.0 && jruby test_autoload.rb

Output

Using /Users/uwe/.rvm/gems/jruby-9.0.5.0
NameError: uninitialized constant ClassB::ModuleC
         <class:ClassB> at /Users/uwe/workspace/aifudis/operator/issue_autoload/class_b.rb:4
                  <top> at /Users/uwe/workspace/aifudis/operator/issue_autoload/class_b.rb:3
                   load at org/jruby/RubyKernel.java:955
        block in (root) at /Users/uwe/.rvm/gems/jruby-9.0.5.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:1
              load_file at /Users/uwe/.rvm/gems/jruby-9.0.5.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:457
       new_constants_in at /Users/uwe/.rvm/gems/jruby-9.0.5.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:647
              load_file at /Users/uwe/.rvm/gems/jruby-9.0.5.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:456
        require_or_load at /Users/uwe/.rvm/gems/jruby-9.0.5.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:354
  load_missing_constant at /Users/uwe/.rvm/gems/jruby-9.0.5.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:494
          const_missing at /Users/uwe/.rvm/gems/jruby-9.0.5.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:184
  load_missing_constant at /Users/uwe/.rvm/gems/jruby-9.0.5.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:526
          const_missing at /Users/uwe/.rvm/gems/jruby-9.0.5.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:184
                  <top> at test_autoload.rb:3

I would expect JRuby to load the ModuleC module like it used to.

@donv
Copy link
Member Author

donv commented Feb 15, 2016

The example has been tested with activesupport 4.2.5.1:

gem install activesupport -v "~>4.2"

@donv
Copy link
Member Author

donv commented Feb 15, 2016

I have added a temporary repository with the example files at https://github.com/DatekWireless/jruby_issue_3669 .

@donv
Copy link
Member Author

donv commented Feb 15, 2016

Successfully tested with JRuby 1.7.24 as well:

rvm use jruby-1.7.24 && jruby test_autoload.rb

Output:

Using /Users/uwe/.rvm/gems/jruby-1.7.24
Success!

@donv
Copy link
Member Author

donv commented Feb 15, 2016

Issue confirmed on master as well:

rvm use jruby-head && jruby -v test_autoload.rb
Using /Users/uwe/.rvm/gems/jruby-head
jruby 9.1.0.0-SNAPSHOT (2.2.3) 2016-02-15 f7e243b Java HotSpot(TM) 64-Bit Server VM 25.72-b15 on 1.8.0_72-b15 +jit [darwin-x86_64]
NameError: uninitialized constant ClassB::ModuleC
         <class:ClassB> at /Users/uwe/workspace/jruby/jruby_issue_3669/class_b.rb:4
                  <top> at /Users/uwe/workspace/jruby/jruby_issue_3669/class_b.rb:3
                   load at org/jruby/RubyKernel.java:955
        block in (root) at /Users/uwe/.rvm/gems/jruby-head/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:1
              load_file at /Users/uwe/.rvm/gems/jruby-head/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:457
       new_constants_in at /Users/uwe/.rvm/gems/jruby-head/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:647
              load_file at /Users/uwe/.rvm/gems/jruby-head/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:456
        require_or_load at /Users/uwe/.rvm/gems/jruby-head/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:354
  load_missing_constant at /Users/uwe/.rvm/gems/jruby-head/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:494
          const_missing at /Users/uwe/.rvm/gems/jruby-head/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:184
  load_missing_constant at /Users/uwe/.rvm/gems/jruby-head/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:526
          const_missing at /Users/uwe/.rvm/gems/jruby-head/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:184
                  <top> at test_autoload.rb:3

@ghost
Copy link

ghost commented Feb 15, 2016

norc@ubuntu:~/git/jruby_issue_3669$ chruby jruby-1.7.24 && jruby test_autoload.rb 
Success!
norc@ubuntu:~/git/jruby_issue_3669$ chruby jruby-9.0.1.0 && jruby test_autoload.rb 
Success!
norc@ubuntu:~/git/jruby_issue_3669$ chruby jruby-9.0.3.0 && jruby test_autoload.rb 
NameError: uninitialized constant ClassB::ModuleC
         <class:ClassB> at /home/norc/git/jruby_issue_3669/class_b.rb:4
                  <top> at /home/norc/git/jruby_issue_3669/class_b.rb:3
                   load at org/jruby/RubyKernel.java:957
        block in (root) at /home/norc/.gem/jruby/2.2.2/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:1
              load_file at /home/norc/.gem/jruby/2.2.2/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:457
       new_constants_in at /home/norc/.gem/jruby/2.2.2/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:647
              load_file at /home/norc/.gem/jruby/2.2.2/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:456
        require_or_load at /home/norc/.gem/jruby/2.2.2/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:354
  load_missing_constant at /home/norc/.gem/jruby/2.2.2/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:494
          const_missing at /home/norc/.gem/jruby/2.2.2/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:184
  load_missing_constant at /home/norc/.gem/jruby/2.2.2/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:526
          const_missing at /home/norc/.gem/jruby/2.2.2/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:184
                  <top> at /home/norc/git/jruby_issue_3669/class_a.rb:
norc@ubuntu:~/git/jruby_issue_3669$ chruby jruby-9.0.5.0 && jruby test_autoload.rb 
NameError: uninitialized constant ClassB::ModuleC
         <class:ClassB> at /home/norc/git/jruby_issue_3669/class_b.rb:4
                  <top> at /home/norc/git/jruby_issue_3669/class_b.rb:3
                   load at org/jruby/RubyKernel.java:955
        block in (root) at /home/norc/.gem/jruby/2.2.3/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:1
              load_file at /home/norc/.gem/jruby/2.2.3/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:457
       new_constants_in at /home/norc/.gem/jruby/2.2.3/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:647
              load_file at /home/norc/.gem/jruby/2.2.3/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:456
        require_or_load at /home/norc/.gem/jruby/2.2.3/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:354
  load_missing_constant at /home/norc/.gem/jruby/2.2.3/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:494
          const_missing at /home/norc/.gem/jruby/2.2.3/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:184
  load_missing_constant at /home/norc/.gem/jruby/2.2.3/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:526
          const_missing at /home/norc/.gem/jruby/2.2.3/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:184
                  <top> at test_autoload.rb:3

@kares kares self-assigned this Feb 16, 2016
@kares kares closed this as completed in de96f4f Feb 16, 2016
@donv
Copy link
Member Author

donv commented Feb 16, 2016

Thanks @kares !

@kares kares added this to the JRuby 9.1.0.0 milestone Feb 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants