JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-6119

Loading a Ruby source file from a subdirectory of a JAR without a directory entry fails

    Details

    • Number of attachments :
      2

      Description

      Same as JRUBY-6077 but for a subdirectory of the apk. May be related to JRUBY-5775 where the APK does not return a JarEntry for directories.

      I suspect JRuby assumes that all jar files have directory entries for all files they contain. This is not a requirement for zip files and jar files.

      The symptom is that for a path to a file in a JAR file without explicit entries for the directories

      File.exists?(path_to_file) gives true

      but

      load path_to_file fails with "no such file to load"

        Activity

        Hide
        Uwe Kubosch added a comment -

        Attached new patch file with "git format-patch -1" after committing the changes.

        Show
        Uwe Kubosch added a comment - Attached new patch file with "git format-patch -1" after committing the changes.
        Hide
        Hiro Asari added a comment -

        Uwe,

        I re-read this and I realized that I was a bit confused about the difference between load and require. The latter searches for files with extensions .so, .rb and others (and only those), while the former searches for files with exactly the specified name.

        To wit:

        $ ls 
        test.rb	test2
        $ ruby -v -e 'load "test"'
        ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
        -e:1:in `load': no such file to load -- test (LoadError)
        	from -e:1
        $ ruby -v -e 'load "test2"'
        ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
        $ ruby -v -e 'require "test"'
        ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
        $ ruby -v -e 'require "test2"'
        ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
        -e:1:in `require': no such file to load -- test2 (LoadError)
        	from -e:1
        

        Given this, then, I am not sure if there is anything to fix.

        $ jar tf jar_with_relative_require1.jar 
        META-INF/
        META-INF/MANIFEST.MF
        foo.rb
        test/require_relative1.rb
        test/require_relative2
        

        For load, we have:

        $ jruby -v -r jar_with_relative_require1.jar -e 'load "test/require_relative1"'
        jruby 1.7.0.dev (ruby-1.8.7-p330) (2011-10-27 565a6d8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_26) [darwin-x86_64-java]
        LoadError: no such file to load -- test/require_relative1
            load at org/jruby/RubyKernel.java:986
          (root) at -e:1
        $ jruby -v -r jar_with_relative_require1.jar -e 'load "test/require_relative2"'
        jruby 1.7.0.dev (ruby-1.8.7-p330) (2011-10-27 565a6d8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_26) [darwin-x86_64-java]
        

        For require:

        $ jruby -v -r jar_with_relative_require1.jar -e 'require "test/require_relative1"'
        jruby 1.7.0.dev (ruby-1.8.7-p330) (2011-10-27 565a6d8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_26) [darwin-x86_64-java]
        $ jruby -v -r jar_with_relative_require1.jar -e 'require "test/require_relative2"'
        jruby 1.7.0.dev (ruby-1.8.7-p330) (2011-10-27 565a6d8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_26) [darwin-x86_64-java]
        LoadError: no such file to load -- test/require_relative2
          require at org/jruby/RubyKernel.java:961
           (root) at -e:1
        
        Show
        Hiro Asari added a comment - Uwe, I re-read this and I realized that I was a bit confused about the difference between load and require . The latter searches for files with extensions .so , .rb and others (and only those), while the former searches for files with exactly the specified name. To wit: $ ls test.rb test2 $ ruby -v -e 'load "test"' ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0] -e:1:in `load': no such file to load -- test (LoadError) from -e:1 $ ruby -v -e 'load "test2"' ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0] $ ruby -v -e 'require "test"' ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0] $ ruby -v -e 'require "test2"' ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0] -e:1:in `require': no such file to load -- test2 (LoadError) from -e:1 Given this, then, I am not sure if there is anything to fix. $ jar tf jar_with_relative_require1.jar META-INF/ META-INF/MANIFEST.MF foo.rb test/require_relative1.rb test/require_relative2 For load , we have: $ jruby -v -r jar_with_relative_require1.jar -e 'load "test/require_relative1"' jruby 1.7.0.dev (ruby-1.8.7-p330) (2011-10-27 565a6d8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_26) [darwin-x86_64-java] LoadError: no such file to load -- test/require_relative1 load at org/jruby/RubyKernel.java:986 (root) at -e:1 $ jruby -v -r jar_with_relative_require1.jar -e 'load "test/require_relative2"' jruby 1.7.0.dev (ruby-1.8.7-p330) (2011-10-27 565a6d8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_26) [darwin-x86_64-java] For require : $ jruby -v -r jar_with_relative_require1.jar -e 'require "test/require_relative1"' jruby 1.7.0.dev (ruby-1.8.7-p330) (2011-10-27 565a6d8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_26) [darwin-x86_64-java] $ jruby -v -r jar_with_relative_require1.jar -e 'require "test/require_relative2"' jruby 1.7.0.dev (ruby-1.8.7-p330) (2011-10-27 565a6d8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_26) [darwin-x86_64-java] LoadError: no such file to load -- test/require_relative2 require at org/jruby/RubyKernel.java:961 (root) at -e:1
        Hide
        Uwe Kubosch added a comment -

        Did you try running the tests in the patch?

        Essentially we fix Dir#entries to work when the directory entry is missing in the JAR file.

        Some other aspects of load/require have been fixed in earlier issues.

        Show
        Uwe Kubosch added a comment - Did you try running the tests in the patch? Essentially we fix Dir#entries to work when the directory entry is missing in the JAR file. Some other aspects of load/require have been fixed in earlier issues.
        Hide
        Hiro Asari added a comment -

        Right.

        I merged the patch to the master (c2d6534) and the 1.6 branch (27b80e3).

        Show
        Hiro Asari added a comment - Right. I merged the patch to the master (c2d6534) and the 1.6 branch (27b80e3).
        Hide
        Uwe Kubosch added a comment -

        Thanks!

        Show
        Uwe Kubosch added a comment - Thanks!

          People

          • Assignee:
            Hiro Asari
            Reporter:
            Uwe Kubosch
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: