Skip to content

ArrayBuilder regression in scala 2.13.13, OutOfMemoryError when adding empty arrays #12971

@alexdupre

Description

@alexdupre

Reproduction steps

Scala version: 2.13.13

The issue is reproducible only on scala 2.13.13, because a recent patch to the ArrayBuilder triggered it, but the incriminated code is probably the same in every scala release: https://github.com/scala/scala/blob/5aa3dc5ea77800ddd2a3bdf9e7feeea57484421c/src/library/scala/collection/mutable/ArrayBuffer.scala#L326-L331

As you can see from the code above, if the targetLen is 0 the array length is doubled.

Here you can find a minimal test-case: https://github.com/alexdupre/scala-2.13.13-bug

Just sbt run to reproduce it.

Problem

OutOfMemoryError because the underlying array is doubled at every iteration even if no elements have been added.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions