Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
toth-istvan-zoltan opened this issue Jul 4, 2024 · 1 comment
Open
2 tasks done
Assignees
Labels
enhancement New feature or request Foundation Related to the base module Plugin Related to the Kotlin compiler plugin

Comments

@toth-istvan-zoltan
Copy link
Contributor

toth-istvan-zoltan commented Jul 4, 2024

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.

  • add to documentation
  • throw compilation error for this case
@toth-istvan-zoltan toth-istvan-zoltan self-assigned this Jul 4, 2024
@toth-istvan-zoltan toth-istvan-zoltan added enhancement New feature or request Plugin Related to the Kotlin compiler plugin Foundation Related to the base module labels Jul 4, 2024
@toth-istvan-zoltan
Copy link
Contributor Author

toth-istvan-zoltan commented Jul 4, 2024

Compilation fails with missing class: kotlin.Array.WireFormat

This is intended for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Foundation Related to the base module Plugin Related to the Kotlin compiler plugin
Projects
None yet
Development

No branches or pull requests

1 participant