Skip to content

_size private property is not incremented in add w/ index in native CopyOnWriteList #1307

Closed
@LouisCAD

Description

@LouisCAD

In the CopyOnWriteList class for Kotlin/Native, the _ size private property is incremented in the add(element: E): Boolean function on line 16:

override fun add(element: E): Boolean {
val newSize = if (_size == array.size) array.size * 2 else array.size
val update = array.copyOf(newSize)
update[_size++] = element
array = update
return true
}

but it is not in the add(index: Int, element: E) function:

override fun add(index: Int, element: E) {
rangeCheck(index)
val update = arrayOfNulls<Any?>(if (array.size == _size) array.size * 2 else array.size)
arraycopy(array, 0, update, 0, index)
update[index] = element
arraycopy(array, index, update, index + 1, _size - index + 1)
array = update
}

I believe this is a bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions