Skip to content

require_relative fails when called from classpath:/ path file on Windows in JRuby 1.7.9 #1374

@rsim

Description

@rsim

This commit 429149e introduced the following issue in JRuby 1.7.9 when running JRuby from jruby-complete-1.7.9.jar on Windows:

C:\>java -cp jruby-complete-1.7.9.jar org.jruby.Main -S jirb
irb(main):001:0> require "classpath:/META-INF/jruby.home/lib/ruby/shared/krypt.rb"
LoadError: no such file to load -- classpath:C:/META-INF/jruby.home/lib/ruby/shared/krypt_missing
        from org/jruby/RubyKernel.java:1083:in `require'
        from jar:file:/C:/Users/raymond/Desktop/jruby-complete-1.7.9.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:55:in `require'
        from file:/C:/Users/raymond/Desktop/jruby-complete-1.7.9.jar!/jruby/kernel19/kernel.rb:21:in `require_relative'
        from classpath:/META-INF/jruby.home/lib/ruby/shared/krypt.rb:37:in `(root)'
        from org/jruby/RubyKernel.java:1083:in `require'
        from jar:file:/C:/Users/raymond/Desktop/jruby-complete-1.7.9.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:1:in `(root)'
        from jar:file:/C:/Users/raymond/Desktop/jruby-complete-1.7.9.jar!/META-INF/jruby.home/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:55:in `require'
        from org/jruby/RubyKernel.java:1119:in `eval'
        from (irb):1:in `evaluate'
        from org/jruby/RubyKernel.java:1519:in `loop'
        from org/jruby/RubyKernel.java:1282:in `catch'
        from org/jruby/RubyKernel.java:1282:in `catch'
        from org/jruby/RubyKernel.java:1099:in `load'
        from file:/C:/Users/raymond/Desktop/jruby-complete-1.7.9.jar!/META-INF/jruby.home/bin/jirb:13:in `(root)'
        from jirb:1:in `(root)'

As a result requiring "openssl" fails. When the mentioned commit is reverted then it is working fine.

The cause for this issue is that File.expand_path adds this C:/ in front of path. require_relative removes classpath: prefix and then calls File.expand_path on /META-INF/jruby.home/lib/ruby/shared and then it adds default drive prefix C:/.

This issue is similar to https://jira.codehaus.org/browse/JRUBY-7122 which was fixed by https://github.com/jruby/jruby/pull/674/files. But currently File.expand_path is fixed to work correctly with classpath: path as first argument but not as second argument:

irb(main):003:0> File.expand_path("classpath:/META-INF/jruby.home/lib/ruby/shared/krypt.rb")
=> "classpath:/META-INF/jruby.home/lib/ruby/shared/krypt.rb"
irb(main):004:0> File.expand_path("krypt.rb", "classpath:/META-INF/jruby.home/lib/ruby/shared")
=> "classpath:C:/META-INF/jruby.home/lib/ruby/shared/krypt.rb"

So it would be good to fix File.expand_path to work correctly also in the second case to avoid other similar issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions