Fixing a Bug in Which Lawnchair crashes due to features value not set. Fix #5337 (#5347)

* Fixing a Bug in Which Lawnchair crashes due to features value not set.

Bug Description
Error:
hf.c: Field 'features' is required for type [...] but it was missing from Issues #5337
Cause:
The LiveInformation class expects a non-null features field during deserialization, but the incoming data (e.g., from cached preferences or an API response) lacks this field. This crashes the app when parsing older data formats or incomplete responses.

Fix
Root Issue:
Kotlinx Serialization requires fields marked as non-optional (no default value) to be present in the input data. The features and announcements fields were missing defaults, causing deserialization failures.

Solution:
Add default values to the LiveInformation data class to ensure backward compatibility with legacy data:


@Serializable
data class LiveInformation(
    private val version: Int = 2,
    val announcements: List<Announcement> = emptyList(), // Default empty list
    val features: Map<String, String?> = emptyMap(),     // Default empty map
) {
    companion object {
        val default = LiveInformation() // Simplified
    }
}

* Fomat Fix and old way of initializing object
This commit is contained in:
Anoni
2025-03-21 03:39:17 +05:30
committed by GitHub
parent 1733d4c05a
commit 9bcd9595da
@@ -5,8 +5,8 @@ import kotlinx.serialization.Serializable
@Serializable
data class LiveInformation(
private val version: Int = 2,
val announcements: List<Announcement>,
val features: Map<String, String?>,
val announcements: List<Announcement> = emptyList(),
val features: Map<String, String?> = emptyMap(),
) {
companion object {