From 00d5fbc6beaa7ae221c409162271131eee14f082 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 3 Sep 2018 11:44:17 +0200 Subject: [PATCH] fix some crashes related to missing Label fields at upgrading from older versions --- .../simplemobiletools/contacts/helpers/DBHelper.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt index 860b3698..26da1385 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/DBHelper.kt @@ -283,14 +283,27 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont val phoneNumbers = if (phoneNumbersJson == "[]") ArrayList() else gson.fromJson>(phoneNumbersJson, phoneNumbersToken) ?: ArrayList(1) + // labels can be null at upgrading from older app versions, when the label wasn't available at all yet + phoneNumbers.filter { it.label == null }.forEach { + it.label = "" + } + val emailsJson = cursor.getStringValue(COL_EMAILS) val emails = if (emailsJson == "[]") ArrayList() else gson.fromJson>(emailsJson, emailsToken) ?: ArrayList(1) + emails.filter { it.label == null }.forEach { + it.label = "" + } + val addressesJson = cursor.getStringValue(COL_ADDRESSES) val addresses = if (addressesJson == "[]") ArrayList() else gson.fromJson>(addressesJson, addressesToken) ?: ArrayList(1) + addresses.filter { it.label == null }.forEach { + it.label = "" + } + val eventsJson = cursor.getStringValue(COL_EVENTS) val events = if (eventsJson == "[]") ArrayList() else gson.fromJson>(eventsJson, eventsToken) ?: ArrayList(1)