chRyNaN / serialization-parcelable

Android Parcelable support for the Kotlinx Serialization library.
Apache License 2.0
70 stars 3 forks source link

NPE in ByteArrayParcel init #2

Closed tadfisher closed 1 year ago

tadfisher commented 2 years ago

The init block in ByteArrayParcel throws an NPE because data is not set when setDataFromByteArray runs.

I'm not sure if this is caused by a compiler change in Kotlin 1.7, because ordinarily you'd get a compiler diagnostic like "data is not initialized".

The easiest fix would be to move the init { } block below where the data property is initialized.

Stacktrace:

Cannot invoke "java.util.List.clear()" because "this.data" is null
java.lang.NullPointerException: Cannot invoke "java.util.List.clear()" because "this.data" is null
    at com.chrynan.parcelable.core.ByteArrayParcel.setDataFromByteArray(ByteArrayParcel.kt:188)
    at com.chrynan.parcelable.core.ByteArrayParcel.<init>(ByteArrayParcel.kt:17)
    at com.chrynan.parcelable.core.ByteArrayParcel.<init>(ByteArrayParcel.kt:14)
    at com.chrynan.parcelable.core.JvmParcelKt.Parcel(JvmParcel.kt:3)
github-actions[bot] commented 2 years ago

Welcome and thanks for contributing! Make sure to leave a detailed explanation of the issue.

chRyNaN commented 1 year ago

@tadfisher Thanks for reporting this issue! This should be fixed in the latest version: https://github.com/chRyNaN/serialization-parcelable/releases/tag/0.5.0