spxbhuhb / adaptive

Consolidated full-stack application development library for Kotlin
https://adaptive.fun
Apache License 2.0
3 stars 0 forks source link

Arrays of non-primitive values crash during runtime in JVM #33

Open toth-istvan-zoltan opened 3 months ago

toth-istvan-zoltan commented 3 months ago

JVM arrays are not really generic, the type of the item they store have to be known at compile time, there is no type erasure.

This means that the current decoder fails during runtime:

Caused by: java.lang.ClassCastException:
class [Ljava.lang.Object; cannot be cast to class [Ljava.util.List; ([Ljava.lang.Object; and [Ljava.util.List; are in module java.base of loader 'bootstrap')
@ServiceApi
interface TestService {
    suspend fun testArray(arg1: Array<List<Int>>) : Array<List<Int>>
}

The code in question is in Collections.kt

return Array(list.size) { list[it] } as Array<T?>

To solve this we have to pass the class the array stores, probably in ArrayWireFormat.

I'll put this on the self for now as non-primitive arrays can be easily replaced with lists.

toth-istvan-zoltan commented 3 months ago

Compilation fails with missing class: kotlin.Array.WireFormat

This is intended for now.