From 719753030175a14ac38266a80deac462410fffe8 Mon Sep 17 00:00:00 2001 From: Tuomas Airaksinen Date: Thu, 9 Nov 2023 14:38:59 +0200 Subject: [PATCH] Fix #3028 (Crash in migration: NullPointerException: cur.getString(1) must not be null) --- .../migrations/DatabaseSplitMigrations.kt | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/db/src/main/java/net/bible/android/database/migrations/DatabaseSplitMigrations.kt b/db/src/main/java/net/bible/android/database/migrations/DatabaseSplitMigrations.kt index 630d3c8e07..e41e2dd3dd 100644 --- a/db/src/main/java/net/bible/android/database/migrations/DatabaseSplitMigrations.kt +++ b/db/src/main/java/net/bible/android/database/migrations/DatabaseSplitMigrations.kt @@ -318,12 +318,12 @@ class DatabaseSplitMigrations(private val oldDb: SupportSQLiteDatabase, val app: query("SELECT id,$workspaceSettings,`text_display_settings_bookmarksHideLabels` FROM new.Workspace").use { cur -> while (cur.moveToNext()) { val id = cur.getBlob(0) - val recentLabels: List = json.decodeFromString(serializer(), cur.getString(1)) - val favouriteLabels: List = json.decodeFromString(serializer(), cur.getString(2)) - val autoAssignLabels: List = json.decodeFromString(serializer(), cur.getString(3)) - val newRecentLabels: String = json.encodeToString(serializer(), recentLabels.mapNotNull { OldRecentLabel -> - val labelId = labelMap[OldRecentLabel.labelId] ?: return@mapNotNull null - NewRecentLabel(IdType.fromByteArray(labelId).toString(), OldRecentLabel.lastAccess) + val recentLabels: List = cur.getStringOrNull(1)?.let {json.decodeFromString(serializer(), it) } ?: emptyList() + val favouriteLabels: List = cur.getStringOrNull(2)?.let { json.decodeFromString(serializer(), it)} ?: emptyList() + val autoAssignLabels: List = cur.getStringOrNull(3)?.let {json.decodeFromString(serializer(), it)} ?: emptyList() + val newRecentLabels: String = json.encodeToString(serializer(), recentLabels.mapNotNull { oldRecentLabel -> + val labelId = labelMap[oldRecentLabel.labelId] ?: return@mapNotNull null + NewRecentLabel(IdType.fromByteArray(labelId).toString(), oldRecentLabel.lastAccess) }) val newFavouriteLabels: String = json.encodeToString(serializer(), favouriteLabels.mapNotNull { val v = labelMap[it] ?: return@mapNotNull null @@ -355,10 +355,9 @@ class DatabaseSplitMigrations(private val oldDb: SupportSQLiteDatabase, val app: query("SELECT windowId,text_display_settings_bookmarksHideLabels FROM new.PageManager WHERE text_display_settings_bookmarksHideLabels IS NOT NULL").use { cur -> while (cur.moveToNext()) { val id = cur.getBlob(0) - val bookmarksHideLabelsStr = cur.getString(1) val newBookmarksHideLabels: String = run { val bookmarksHideLabels: List = - json.decodeFromString(serializer(), bookmarksHideLabelsStr) + cur.getStringOrNull(1)?.let {json.decodeFromString(serializer(), it) } ?: emptyList() json.encodeToString(serializer(), bookmarksHideLabels.mapNotNull { labelMap[it] }) } update("new.PageManager", CONFLICT_ABORT, ContentValues().apply {