Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix StackOverflowError in Page.latest
Fixes #64
  • Loading branch information
filipochnik committed Jan 30, 2019
commit 334419d6d2a62089943a535cbd479d7cc35b8de2
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,12 @@ private class Page[T: ClassTag](val num: Int) {
/** The last page as currently present in the sequence; This can change as more
* elements get appended to the sequence. */
final def latest: Page[T] = {
if (later.next != null) later = later.next.latest
var oldLater = later
while (later.next != null) later = later.next
while (oldLater.next != null) {
oldLater = oldLater.next
oldLater.later = later
}
later
}

Expand Down
16 changes: 16 additions & 0 deletions shared/src/test/scala/scala/util/parsing/input/gh64.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package scala.util.parsing.input

import org.junit.Assert._
import org.junit.Test

class gh64 {

@Test
def test: Unit = {
val len = 4096 * 20000
val i = Iterator.fill(len)(true) // use `true` to make this test more lightweight
val pagedSeq = PagedSeq.fromIterator(i)
pagedSeq.slice(len - 1) // load the whole pagedSeq without caching `latest` element
assertEquals(len, pagedSeq.length) // should not throw StackOverflowError
}
}