Do not leak primitiveness of an array wrapped with asList
A primitive array wrapped in a List with asList had incorrect implementation of toArray method: while it declares that an object array is returned, it returned a primitive array. Therefore the methods such as `Collection.toTypedArray()` and its dependents `ArrayList(collection)`, `Collection + Iterable` might behave incorrectly having relied on `toTypedArray` returned an object array. #KT-21828 Fixed
This commit is contained in:
@@ -36,6 +36,13 @@ class JsCollectionsTest {
|
||||
snapshotDoesNotCreateView(arrayOf<Any>("first", "last"), { arrayListOf(*it) })
|
||||
}
|
||||
|
||||
@Suppress("USELESS_CAST")
|
||||
@Test fun asListHidesPrimitivenessOfArray() {
|
||||
assertTrue(intArrayOf(1).asList().toTypedArray() as Any is Array<*>, "IntArray primitiveness leaks")
|
||||
assertTrue(longArrayOf(1).asList().toTypedArray() as Any is Array<*>, "LongArray primitiveness leaks")
|
||||
assertTrue(charArrayOf(' ').asList().toTypedArray() as Any is Array<*>, "CharArray primitiveness leaks")
|
||||
}
|
||||
|
||||
@Test fun arrayListCapacity() {
|
||||
val list = ArrayList<Any>(20)
|
||||
list.ensureCapacity(100)
|
||||
|
||||
Reference in New Issue
Block a user