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

File.new (and related paths) unconditionally calling to_int on first arg

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.6
    • Fix Version/s: JRuby 1.6.1
    • Component/s: Core Classes/Modules
    • Labels:
      None
    • Number of attachments :
      0

      Description

      From this sample script:

      # From https://github.com/rspec/rspec-core/issues/195 
      # and patched (unsuccessfully on JRuby) in https://github.com/rspec/rspec-core/issues/295
      
      String.send :alias_method, :to_int, :to_i
      
      puts File.readlines(__FILE__).empty? # is false on 1.8 and 1.9, true on JRuby 1.6.0
      

      The problem is that we're unconditionally attempting to coerce to a file descriptor with to_int, so it opens the wrong thing and blocks forever trying to read. The following is a quick patch, but I haven't investigated whether it's 100% sound:

      diff --git a/src/org/jruby/RubyFile.java b/src/org/jruby/RubyFile.java
      index ae5d8e3..e50268b 100755
      --- a/src/org/jruby/RubyFile.java
      +++ b/src/org/jruby/RubyFile.java
      @@ -424,10 +424,8 @@ public class RubyFile extends RubyIO implements EncodingCapable {
               }
               
               if (args.length > 0 && args.length < 3) {
      -            IRubyObject fd = TypeConverter.convertToTypeWithCheck(args[0], getRuntime().getFixnum(), "to_int");
      -            if (!fd.isNil()) {
      -                args[0] = fd;
      -                return super.initialize(args, block);
      +            if (args[0] instanceof RubyInteger) {
      +                return super.initialize(new IRubyObject[] {args[0]}, block);
                   }
               }
       
      

        Activity

        Hide
        Charles Oliver Nutter added a comment -

        commit 3037c5e6f54b71844f9786fdefe21b941385a457
        Author: Charles Oliver Nutter <headius@headius.com>
        Date: Wed Mar 23 19:32:02 2011 -0500

        Fix JRUBY-5634: File.new (and related paths) unconditionally calling to_int on first arg

        Show
        Charles Oliver Nutter added a comment - commit 3037c5e6f54b71844f9786fdefe21b941385a457 Author: Charles Oliver Nutter <headius@headius.com> Date: Wed Mar 23 19:32:02 2011 -0500 Fix JRUBY-5634 : File.new (and related paths) unconditionally calling to_int on first arg

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Charles Oliver Nutter
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: