Skip to content

Fix StackOverflowError in Page.latest #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2019
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
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
}
}