Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.6
    • Fix Version/s: JRuby 1.6.1
    • Component/s: Core Classes/Modules, Intro
    • Labels:
      None
    • Environment:
      jruby 1.6.0 (ruby 1.8.7 patchlevel 330) (2011-03-15 f3b6154) (OpenJDK Client VM 1.6.0_20) [linux-i386-java]
    • Testcase included:
      yes
    • Number of attachments :
      1

      Description

      In MRI the Dir#pos= method accepts a negative value. It's effectively a no-op if a read has not occurred yet, or returns nil if at least one read has already occurred, which I assume moves the pointer to the end of the stream. The behavior is curious, and I suspect it's driven by the rules of the underlying seekdir() function, though I haven't thoroughly scoured the source, and the man page for seekdir() made no mention of negative values.

      JRuby fails with an Java::JavaLang::ArrayIndexOutOfBoundsException.

      I've attached the test suite I'm using for berger_spec.

        Activity

        Hide
        Hiro Asari added a comment -

        I haven't looked at the source, but from the sound of it, it should be pretty straightforward to fix.

        Show
        Hiro Asari added a comment - I haven't looked at the source, but from the sound of it, it should be pretty straightforward to fix.
        Hide
        Charles Oliver Nutter added a comment - - edited

        This is weird...I can't tell that it does anything at all:

        ~/projects/jruby ➔ ruby -e "dir = Dir.new(File.dirname(__FILE__)); dir.pos = -1; p dir.read; dir.pos = -1; p dir.read; dir.pos = -1; p dir.read"
        "."
        ".."
        ".classpath"
        
        ~/projects/jruby ➔ ruby -e "dir = Dir.new(File.dirname(__FILE__)); p dir.read; p dir.read; p dir.read"
        "."
        ".."
        ".classpath"
        
        Show
        Charles Oliver Nutter added a comment - - edited This is weird...I can't tell that it does anything at all: ~/projects/jruby ➔ ruby -e "dir = Dir.new(File.dirname(__FILE__)); dir.pos = -1; p dir.read; dir.pos = -1; p dir.read; dir.pos = -1; p dir.read" "." ".." ".classpath" ~/projects/jruby ➔ ruby -e "dir = Dir.new(File.dirname(__FILE__)); p dir.read; p dir.read; p dir.read" "." ".." ".classpath"
        Hide
        Charles Oliver Nutter added a comment -

        At least one article says a negative value passed to seekdir does nothing at all.

        http://publib.boulder.ibm.com/infocenter/zos/v1r10/index.jsp?topic=/com.ibm.zos.r10.bpxbd00/rsekdr.htm

        I'll make us match.

        Show
        Charles Oliver Nutter added a comment - At least one article says a negative value passed to seekdir does nothing at all. http://publib.boulder.ibm.com/infocenter/zos/v1r10/index.jsp?topic=/com.ibm.zos.r10.bpxbd00/rsekdr.htm I'll make us match.
        Hide
        Charles Oliver Nutter added a comment -

        commit 88e0b0075f417cfad43ef7baa9e9fe74f2ecc7ac
        Author: Charles Oliver Nutter <headius@headius.com>
        Date: Thu Mar 31 17:53:01 2011 -0500

        Fix JRUBY-5640: Dir#pos= dies if negative value provided

        Show
        Charles Oliver Nutter added a comment - commit 88e0b0075f417cfad43ef7baa9e9fe74f2ecc7ac Author: Charles Oliver Nutter <headius@headius.com> Date: Thu Mar 31 17:53:01 2011 -0500 Fix JRUBY-5640 : Dir#pos= dies if negative value provided
        Hide
        Daniel Berger added a comment -

        That's what I figured. Thanks for the link. I need to double check MRI's behavior on this.

        Show
        Daniel Berger added a comment - That's what I figured. Thanks for the link. I need to double check MRI's behavior on this.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: