lists auto convert to arrays hide bugs

We try to leverage coroutines to boost some apps performance, first “Convert Java File to Kotlin File”,
but faint, there is a hide deeply bug.
original Java:

private void bulkInsert(Uri uri, List<ContentValues> insertBulk) {
    if (insertBulk == null || insertBulk.size() == 0) return;
    ContentValues[] values = new ContentValues[insertBulk.size()];
    insertBulk.toArray(values);  
    getContentResolver().bulkInsert(uri, values);
}

automatically converted Kotlin:

private fun bulkInsert(uri: Uri, insertBulk: List<ContentValues>?) {
    if (insertBulk == null || insertBulk.size == 0) return
    val values = arrayOfNulls<ContentValues>(insertBulk.size)
    insertBulk.toTypedArray() // **lost assignment to values**
    contentResolver.bulkInsert(uri, values)
}

however the corrected must be:

val values = insertBulk.toTypedArray()

From list to arrays, it is lost assigment to that array (here is values) !

Moreover, ArrayList(size) and MutableList(size) { null } shock us.

var subMediaSet: MutableList<String?>
subMediaSet = ArrayList(10)  // OhMyGod,it's [] ,size = 0
//subMediaSet = MutableList(10) { null } // only this way is 10-nulls list

println(subMediaSet)
println(subMediaSet.size)

We use the IDE is Android Studio 3.2 or IntelliJ IDEA 2018.2.

From list to arrays, it is lost assigment to that array (here is values) !

Please vote/follow this issue: https://youtrack.jetbrains.com/issue/KT-20534

Moreover, ArrayList(size) and MutableList(size) { null } shock us.

Can you please create a new issue here: http://kotl.in/issue with sample code before and after conversion? I couldn’t find a relevant issue for this case. Thank you.

1 Like

Ok, First voted.
Second, cteated: https://youtrack.jetbrains.com/issue/KT-28396

1 Like