Scala Programming Language
  1. Scala Programming Language
  2. SI-4662

Regression: Source.getLines broken in 2.9.0.1

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.9.0
    • Fix Version/s: None
    • Component/s: Misc Library
    • Labels:
      None
    • Environment:

      OS X 10.6.7, Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_24

      Description

      Source.getLines appears to be... entirely broken. I have a very simple test case: a plain-jain text file of three lines save in normal utf-8. Calling .getLines on the Source from this File does nothing: an empty iterator, no lines at all. However, it has no problem iterating over the chars.

      This is a regression, it worked without a problem in 2.8. This paste shows exactly the problem and compares with 2.8:

      http://pastie.org/2000844

        Activity

        Hide
        Daniel Sobral added a comment - - edited

        That's a different bug, really, but I'm not in any position to tell you whether to open a new bug or not.

        The solution you provided is still suboptimal, however, because whenever you call "next", it will only return after the the following line has read. In other words, you fixed it for first/second line, but it will still happen with second/third, third/fourth, etc. For an example of the sort of problem this can give, see SI-4599.

        I think the following would fix it for next:

          override def next(): String = {
            if (unread) {
              nextLine = bufReader.readLine
            }
            unread = true
            nextLine
          }
        
        Show
        Daniel Sobral added a comment - - edited That's a different bug, really, but I'm not in any position to tell you whether to open a new bug or not. The solution you provided is still suboptimal, however, because whenever you call "next", it will only return after the the following line has read. In other words, you fixed it for first/second line, but it will still happen with second/third, third/fourth, etc. For an example of the sort of problem this can give, see SI-4599 . I think the following would fix it for next : override def next(): String = { if (unread) { nextLine = bufReader.readLine } unread = true nextLine }
        Hide
        Commit Message Bot added a comment -

        (extempore in r25212) Keep BufferedSource from losing buffered data when a derivative iterator
        is created via getLines. Closes #4671, #4662, no review.

        Show
        Commit Message Bot added a comment - (extempore in r25212 ) Keep BufferedSource from losing buffered data when a derivative iterator is created via getLines. Closes #4671, #4662, no review.
        Hide
        Viktor Hedefalk added a comment -

        I'm still having problems with this on 2.9.2r25743-b20110928032420 from within the scala-ide:

        @RunWith(classOf[JUnitRunner])
        class SourceTest extends FlatSpec with ShouldMatchers with Logger {
          import scala.io.Source._
          it should "not frikkin eat it up" in {
            val source = fromInputStream(this.getClass.getResourceAsStream("fileWithTwoLines"))(Codec.UTF8)
            debug("source: " + source)
            val lines = source.getLines()
            debug("lines.hasNext: " + lines.hasNext)
            debug("lines size: " + lines.size)
            debug("lines: " + lines)
            debug("lines.hasNext: " + lines.hasNext)
            for(line <- lines) yield (debug("line: " + line))
          }
        }
        

        yields the following log:

        
        16:40:54.576 [main] DEBUG test.SourceTest - source: non-empty iterator
        16:40:54.583 [main] DEBUG test.SourceTest - lines.hasNext: true
        16:40:54.584 [main] DEBUG test.SourceTest - lines size: 2
        16:40:54.585 [main] DEBUG test.SourceTest - lines: empty iterator
        16:40:54.585 [main] DEBUG test.SourceTest - lines.hasNext: false
        
        
        Show
        Viktor Hedefalk added a comment - I'm still having problems with this on 2.9.2r25743-b20110928032420 from within the scala-ide: @RunWith(classOf[JUnitRunner]) class SourceTest extends FlatSpec with ShouldMatchers with Logger { import scala.io.Source._ it should "not frikkin eat it up" in { val source = fromInputStream(this.getClass.getResourceAsStream("fileWithTwoLines"))(Codec.UTF8) debug("source: " + source) val lines = source.getLines() debug("lines.hasNext: " + lines.hasNext) debug("lines size: " + lines.size) debug("lines: " + lines) debug("lines.hasNext: " + lines.hasNext) for(line <- lines) yield (debug("line: " + line)) } } yields the following log: 16:40:54.576 [main] DEBUG test.SourceTest - source: non-empty iterator 16:40:54.583 [main] DEBUG test.SourceTest - lines.hasNext: true 16:40:54.584 [main] DEBUG test.SourceTest - lines size: 2 16:40:54.585 [main] DEBUG test.SourceTest - lines: empty iterator 16:40:54.585 [main] DEBUG test.SourceTest - lines.hasNext: false
        Hide
        Paul Phillips added a comment -

        You can't call "size" on an Iterator without exhausting the iterator.

        Show
        Paul Phillips added a comment - You can't call "size" on an Iterator without exhausting the iterator.
        Hide
        Viktor Hedefalk added a comment -

        Hehe, thanks. I must be tired. I blame the missing parens

        Show
        Viktor Hedefalk added a comment - Hehe, thanks. I must be tired. I blame the missing parens

          People

          • Assignee:
            Paul Phillips
            Reporter:
            Paul Lambert
          • Votes:
            4 Vote for this issue
            Watchers:
            10 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development