@@ -19,7 +19,7 @@ import java.lang.{StringBuilder => JStringBuilder}
19
19
20
20
import scala .annotation .tailrec
21
21
import scala .collection .generic .SerializeEnd
22
- import scala .collection .mutable .{ArrayBuffer , Builder , ReusableBuilder , StringBuilder }
22
+ import scala .collection .mutable .{Builder , ReusableBuilder , StringBuilder }
23
23
import scala .language .implicitConversions
24
24
import scala .runtime .Statics
25
25
@@ -1353,7 +1353,7 @@ object LazyList extends SeqFactory[LazyList] {
1353
1353
private [this ] def writeObject (out : ObjectOutputStream ): Unit = {
1354
1354
out.defaultWriteObject()
1355
1355
var these = coll
1356
- while (these.knownNonEmpty) {
1356
+ while (these.knownNonEmpty) {
1357
1357
out.writeObject(these.head)
1358
1358
these = these.tail
1359
1359
}
@@ -1363,14 +1363,17 @@ object LazyList extends SeqFactory[LazyList] {
1363
1363
1364
1364
private [this ] def readObject (in : ObjectInputStream ): Unit = {
1365
1365
in.defaultReadObject()
1366
- val init = new ArrayBuffer [A ]
1366
+ val init = new mutable. ListBuffer [A ]
1367
1367
var initRead = false
1368
1368
while (! initRead) in.readObject match {
1369
1369
case SerializeEnd => initRead = true
1370
1370
case a => init += a.asInstanceOf [A ]
1371
1371
}
1372
1372
val tail = in.readObject().asInstanceOf [LazyList [A ]]
1373
- coll = init ++: tail
1373
+ // scala/scala#10118: caution that no code path can evaluate `tail.state`
1374
+ // before the resulting LazyList is returned
1375
+ val it = init.toList.iterator
1376
+ coll = newLL(stateFromIteratorConcatSuffix(it)(tail.state))
1374
1377
}
1375
1378
1376
1379
private [this ] def readResolve (): Any = coll
0 commit comments