Skip to content

Commit 1986ed2

Browse files
committed
Merge pull request #4758 from lrytz/pagedSeqNpe
Fix NPE in PagedSeq.slice at end of seq
2 parents b626af6 + 8cca2bc commit 1986ed2

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/library/scala/collection/immutable/PagedSeq.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ extends scala.collection.AbstractSeq[T]
190190
val e = if (_end == UndeterminedEnd) _end else start + _end
191191
var f = first1
192192
while (f.end <= s && !f.isLast) {
193-
if (f.next eq null) f.addMore(more)
194-
f = f.next
193+
if (f.next eq null) f = f.addMore(more)
194+
else f = f.next
195195
}
196196
// Warning -- not refining `more` means that slices can freely request and obtain
197197
// data outside of their slice. This is part of the design of PagedSeq

test/junit/scala/collection/immutable/PagedSeqTest.scala

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ class PagedSeqTest {
1313
assertEquals(Seq('a'), PagedSeq.fromStrings(List.fill(5000)("a")).slice(4096, 4097))
1414
}
1515

16+
// should not NPE, and should be empty
17+
@Test
18+
def test_SI9480(): Unit = {
19+
assertEquals(Seq(), PagedSeq.fromStrings(List("a")).slice(1))
20+
}
21+
1622
// Slices shouldn't read outside where they belong
1723
@Test
1824
def test_SI6519 {

0 commit comments

Comments
 (0)