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

PagedSeq's slice throws a NPE if it starts on a page that hasn't been computed yet

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.9.2, Scala 2.10.0-RC1
    • Fix Version/s: Scala 2.11.0-M8
    • Component/s: Collections
    • Labels:

      Description

      Trying to take a slice of a PagedSeq that starts on a page that hasn't been computed yet throws a NullPointerException. For example, the following works as expected:

      scala> import scala.collection.immutable.PagedSeq
      import scala.collection.immutable.PagedSeq
      
      scala> PagedSeq.fromStrings(List.fill(5000)("a")).slice(4095, 4096)
      res0: scala.collection.immutable.PagedSeq[Char] = PagedSeq(a)
      

      But if we start one character later in the sequence (at the beginning of the second page), we get the following:

      scala> PagedSeq.fromStrings(List.fill(5000)("a")).slice(4096, 4097)
      java.lang.NullPointerException
              at scala.collection.immutable.PagedSeq.slice(PagedSeq.scala:189)
              at .<init>(<console>:9)
              at .<clinit>(<console>)
              ...
      

      The error does not occur if you force the second page to be computed (by calling toString or length, for example) before calling slice:

      scala> val s = PagedSeq.fromStrings(List.fill(5000)("a"))
      s: scala.collection.immutable.PagedSeq[Char] = PagedSeq(a, a, a,  ...
      scala> s.slice(4096, 4097)
      res2: scala.collection.immutable.PagedSeq[Char] = PagedSeq(a)
      

        Activity

        Hide
        Josh Suereth added a comment -

        Note: This isn't a blocker for 2.10.0, but we'll try to fix it in 2.10.1

        Show
        Josh Suereth added a comment - Note: This isn't a blocker for 2.10.0, but we'll try to fix it in 2.10.1
        Hide
        James Iry added a comment -

        Not a regression in 2.10.2 and not a blocker so not a candidate for RC2

        Show
        James Iry added a comment - Not a regression in 2.10.2 and not a blocker so not a candidate for RC2
        Show
        Adriaan Moors added a comment - https://github.com/scala/scala/pull/3303

          People

          • Assignee:
            Rex Kerr
            Reporter:
            Travis Brown
          • Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development