Skip to content

Require is not working for .class file if the class is inside a module since 9.3.0 #8758

@sachinswagh

Description

@sachinswagh

I'm converting .rb files to .class files using jrubyc and using it inside another .rb file.
It used to work as expected up to 9.2.21. But since 9.3.0 its not working. Also tried with the latest 9.4.12 version, same error.

Repro:

bar.rb

module Foo
  class Bar
    def test
      puts "Called test from foo::bar"
    end
  end
end

test.rb

require 'java'
require './bar.class'

bar = Foo::Bar.new
bar.test

Commands used:

jrubyc bar.rb
jruby test.rb

Actual Behavior

Output on jruby 9.2.21 --
File gets loaded successfully
Called test from foo::bar

Output on 9.3.0 & 9.4.x

org/jruby/RubyKernel.java:1184:in `require': ←[1mno such file to load -- ./bar.class (←[1;4mLoadError←[m←[1m)←[m
        from C:/Users/sachin_wagh/Projects/jruby-6.1_9.4.8.0/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:85:in `require'
        from test.rb:4:in `<main>'

I've also tried using java_require instead of require, but that just changes the error to -

org/jruby/RubyModule.java:4338:in `const_missing': ←[1muninitialized constant Foo (←[1;4mNameError←[m←[1m)←[m
        from test.rb:4:in `<main>'

I've also tried using java_package but did not get the expected result.
I'm using windows but I've seen similar output on linux as well.

Expected Behavior
Should have worked similar to 9.2.21

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions