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

                 Key: JRUBY-5634
                 URL: http://jira.codehaus.org/browse/JRUBY-5634
             Project: JRuby
          Issue Type: Bug
          Components: Core Classes/Modules
    Affects Versions: JRuby 1.6
            Reporter: Charles Oliver Nutter
             Fix For: JRuby 1.6.1


>From this sample script:

{noformat}
# 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
{noformat}

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:

{noformat}

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);
             }
         }
 
{noformat}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to