kotlinx.serialization icon indicating copy to clipboard operation
kotlinx.serialization copied to clipboard

Primitives.kt RuntimeError: dereferencing a null pointer

Open VladislavSumin opened this issue 1 year ago • 8 comments

The kotlin-serialization library crashes with a null pointer exception when initializing the Serializer in the code of a third-party library compiled with an older version of kotlin. When using such Serializers directly in the code, there is no crash.

wasm stack trace
Primitives.kt:79 Uncaught (in promise) RuntimeError: dereferencing a null pointer
    at <vs-control.client:wasm>.kotlinx.serialization.internal.checkName (Primitives.kt:79:36)
    at <vs-control.client:wasm>.kotlinx.serialization.internal.PrimitiveDescriptorSafe (Primitives.kt:72:5)
    at <vs-control.client:wasm>.kotlinx.serialization.descriptors.PrimitiveSerialDescriptor (SerialDescriptors.kt:91:12)
    at <vs-control.client:wasm>.com.arkivanov.essenty.statekeeper.Serializer.<init> (SerializableContainer.kt:66:53)
    at <vs-control.client:wasm>.com.arkivanov.essenty.statekeeper.Serializer_getInstance (vs-control-client-wasm-wasm-js.wasm:0x2f6155)
    at <vs-control.client:wasm>.com.arkivanov.decompose.router.children.Companion.<init> (vs-control-client-wasm-wasm-js.wasm:0x2fccd2)
    at <vs-control.client:wasm>.com.arkivanov.decompose.router.children.Companion_getInstance (vs-control-client-wasm-wasm-js.wasm:0x2fcd08)
    at <vs-control.client:wasm>.com.arkivanov.decompose.router.children.childrenNavigator (vs-control-client-wasm-wasm-js.wasm:0x2fcab5)
    at <vs-control.client:wasm>.com.arkivanov.decompose.router.children.children (ChildrenFactory.kt:127:25)
    at <vs-control.client:wasm>.com.arkivanov.decompose.router.children.children$default (vs-control-client-wasm-wasm-js.wasm:0x2fc3ec)

Environment

  • Kotlin version: 2.0.0-Beta4
  • Library version: 1.6.2
  • Kotlin platforms: WASM
  • Gradle version: 8.6
  • Other relevant context: Decompose 3.0.0-alpha07

VladislavSumin avatar Feb 29 '24 20:02 VladislavSumin

Do you have a project with a reproducer, by any chance? It's hard to tell what happened from the stacktrace alone.

sandwwraith avatar Mar 01 '24 11:03 sandwwraith

Yes, I have a project with 100 percent reproduction. You need to rollback to the specified commit and call gradle :client:wasm:wasmJsBrowserDevelopmentRun. It crashes immediately at the start, you don’t need to do anything additional. If you roll back one more commit earlier, kotlin-beta01 will be there and everything works. Repo: https://github.com/VladislavSumin/vs-control Revision: c2257bc76d9a8ad68f1460e361dadb511593b1fa

VladislavSumin avatar Mar 01 '24 18:03 VladislavSumin

I'm receiving the same error

dereferencing a null pointer RuntimeError: dereferencing a null pointer at DroidJobsKMP:webApp-wasm.kotlinx.serialization.internal.checkName (http://localhost:8080/webApp-wasm.wasm:wasm-function[57078]:0x89fe45)

ismai117 avatar Mar 11 '24 17:03 ismai117

I'm also receiving a similar error with serialization and WASM when using Beta4

Shanezor12 avatar Mar 21 '24 06:03 Shanezor12

I was able to reproduce the error, but it seems it is connected to Kotlin/WASM itself. Has anyone reported it to the YouTrack?

sandwwraith avatar Mar 26 '24 12:03 sandwwraith

It seems to be fixed with Kotlin version 2.0.0-Beta5, and I no longer receive the error. If you want to use 2.0.0-Beta5, compose compiler 1.5.11-kt-2.0.0-Beta5 works. 

ismai117 avatar Mar 27 '24 06:03 ismai117

@VladislavSumin Can you confirm that using 2.0.0-Beta5 indeed solves the issue?

sandwwraith avatar Mar 27 '24 16:03 sandwwraith

@sandwwraith Yes I get the same error with the kotlin version Beta5

VladislavSumin avatar Mar 31 '24 18:03 VladislavSumin