You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code is used by SmallPersistentVector to create persistent list by some collection.
val newBuffer = buffer.copyOf(size + elements.size)
// TODO: investigate performance of elements.toArray + copyInto
var index = size
for (element in elements) {
newBuffer[index++] = element
}
return SmallPersistentVector(newBuffer)
The issue is that concurrent collections in Java are weakly consistent.
So, you create a buffer with a size that is immediately incorrect.
So, you have weird runtime bugs like NPE or array index issues.
As the project uses Gradle, I am not yet able to manage to open it in IDEA and write a test.
JDK (List.copyOf) uses toArray ((List<E>)List.of(coll.toArray())), which is a safe and efficient solution.
The text was updated successfully, but these errors were encountered:
develar
changed the title
concurrentList.toPersistentList or toConcurrentMap.toPersistentList is incorrectly implemented
concurrentList.toPersistentList or concurrentMap.toPersistentMap is incorrectly implemented
Nov 2, 2023
Hi, Thanks for reporting the issue.
The library does not prioritise correct handling of concurrent collections.
So it becomes the user responsibility to make sure the elements collection consistency.
It might make sense to pass a snapshot of your concurrent collection to the function instead.
The following code is used by
SmallPersistentVector
to create persistent list by some collection.The issue is that concurrent collections in Java are weakly consistent.
So, you create a buffer with a size that is immediately incorrect.
So, you have weird runtime bugs like NPE or array index issues.
As the project uses Gradle, I am not yet able to manage to open it in IDEA and write a test.
JDK (List.copyOf) uses
toArray
((List<E>)List.of(coll.toArray())
), which is a safe and efficient solution.The text was updated successfully, but these errors were encountered: