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

Closed
rsim opened this Issue Dec 31, 2013 · 4 comments

Projects

None yet

4 participants

@rsim
rsim commented Dec 31, 2013

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.

@rsim rsim referenced this issue Dec 31, 2013
@enebo enebo Classpath urls should still use expand_path to properly canonicalize …
…the path. This fixes no reported issue
429149e
@enebo
Member
enebo commented Dec 31, 2013

I will fix this for sure for 1.7.10. Could someone whip up a test for me so we can get a regression test on this? classpath: and windows is a minefield...

@chrisrgue

I am having a similar issue: trying to deploy the exact same jar file (created by warbler [gemjar]) which is containing the 'xml-smart' gem (in addition to the gems this gems depends on) any files within the 'xml-smart' gem folder (within the jar) cannot be loaded under WINDOWS/CYGWIN (when launching the resulting jar file via: java -jar <JAL_FILE>) although everything works perfectly under linux.
Could this be related ?
Any help is very much appreciated.

@enebo
Member
enebo commented Jan 7, 2014

I reverted this change now. So things should be working as before in 1.7.8. I was going to fix File.expand_path but once I got into it I found a bunch of other ambiguous corner cases. Hopefully for 1.7.11 I can reapply this fix and also better spec out File.expand_path for the uri-type things only JRuby supports.

@enebo enebo closed this Jan 7, 2014
@munkyboy
munkyboy commented Feb 4, 2014

FYI, revert is commit 39056c6

@enebo enebo modified the milestone: JRuby 1.7.10, JRuby 1.7.11 Feb 24, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment