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

TypeError: can't convert Pathname into String - JRuby in 1.9 mode not handling Pathname in $LOAD_PATH consistently with MRI

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.6.4, JRuby 1.6.5
    • Fix Version/s: JRuby 1.7.0.pre1
    • Component/s: None
    • Labels:
      None
    • Environment:
      I'm on OS X 10.6 Java SE 1.6.0_24 (don't think it matters much)
    • Testcase included:
      yes
    • Number of attachments :
      1

      Description

      $ rvm use jruby
      Using lenny/.rvm/gems/jruby-1.6.4
      $ ruby ./test.rb 
      TypeError: can't convert Pathname into String
        require at org/jruby/RubyKernel.java:1047
        require at lenny/.rvm/rubies/jruby-1.6.4/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:29
         (root) at lenny/test.rb:3
      
      $ rvm use 1.9.2
      Using lenny/.rvm/gems/ruby-1.9.2-p290
      bash-3.2$ ruby ./test.rb 
      <internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- foo (LoadError)
      	from <internal:lib/rubygems/custom_require>:29:in `require'
      	from lenny/test.rb:3:in `<main>'
      

      Seems like others have run into this, but I didn't find any previous solutions or tickets:

      http://www.google.com/search?q=TypeError:+can't+convert+Pathname+into+String

      I ran into this while attempting to port a Rails 3 app from Ruby 1.8.7 to 1.9. Tough to track down because the stack trace is of little help when mixed up with Rails Dependencies loading, but I did eventually pin it at:

      src/org/jruby/runtime/load/LoadService.java" line 1169 (as of commit a8652d580 Thu Jan 26)
      RubyString entryString = loadPath.eltInternal(i).convertToString();
      
      In the case of a Pathname in the Loadpath it wound up invoking RubyBaseObject#convertToString
      
      // org/jruby/RubyBasicObject.java
      public RubyString convertToString() {
         return (RubyString) TypeConverter.convertToType(this, getRuntime().getString(), "to_str");
      }
      

      This monkey-patch to Pathname cleared it up for me:

      require 'pathname'
      
      Pathname.class_eval do
        def to_str
          to_s
        end
      end
      
      1. test.rb
        0.1 kB
        Lenny Marks

        Activity

        Hide
        Austin Ziegler added a comment -

        I'm definitely seeing this as well; it's present in 1.6.7 (jruby --1.9 fail_app.rb) and in 1.7.0.

        # -*- ruby encoding: utf-8 -*-
        
        require 'pathname'
        
        SOURCE = Pathname.new(__FILE__).dirname
        $:.unshift SOURCE.join('lib')
        
        require 'fail_require'
        
        Show
        Austin Ziegler added a comment - I'm definitely seeing this as well; it's present in 1.6.7 (jruby --1.9 fail_app.rb) and in 1.7.0. # -*- ruby encoding: utf-8 -*- require 'pathname' SOURCE = Pathname.new(__FILE__).dirname $:.unshift SOURCE.join('lib') require 'fail_require'
        Hide
        Joe Van Dyk added a comment -
        Show
        Joe Van Dyk added a comment - I get the error as well. My backtrace: https://raw.github.com/gist/2315184/4b20461ab41b8b1aab5a883a52df90bab3478c59/gistfile1.txt
        Hide
        Charles Oliver Nutter added a comment -

        I think we need a test for this added to RubySpec. Someone do that please...I'm swamped at the moment

        commit 28be3688b58a61fef305064b2e2bc0f66a0e4de4
        Author: Mateusz Lenik <mt.lenik@gmail.com>
        Date:   Sun Apr 1 09:48:53 2012 +0200
        
            Fixes issue JRUBY-6389
            
            Fixes TypeError when $LOAD_PATH has non-string
            element with `to_path` method.
            JRuby behaviour is now compatible with MRI.
            
            Conflicts:
            
            	src/org/jruby/runtime/load/LoadService.java
        
        Show
        Charles Oliver Nutter added a comment - I think we need a test for this added to RubySpec. Someone do that please...I'm swamped at the moment commit 28be3688b58a61fef305064b2e2bc0f66a0e4de4 Author: Mateusz Lenik <mt.lenik@gmail.com> Date: Sun Apr 1 09:48:53 2012 +0200 Fixes issue JRUBY-6389 Fixes TypeError when $LOAD_PATH has non-string element with `to_path` method. JRuby behaviour is now compatible with MRI. Conflicts: src/org/jruby/runtime/load/LoadService.java
        Hide
        Mateusz Lenik added a comment -

        Actually, there is a test for this in RubySpec.

        Show
        Mateusz Lenik added a comment - Actually, there is a test for this in RubySpec.
        Hide
        Charles Oliver Nutter added a comment -

        Oh, excellent I'll see about untagging it then.

        Show
        Charles Oliver Nutter added a comment - Oh, excellent I'll see about untagging it then.

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Lenny Marks
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: