From b962751c962b5e996223e2eec5f7672d995dfd4e Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Fri, 15 Feb 2019 19:25:20 -0800 Subject: [PATCH] Fix possible IllegalArgumentException during a database migration. --- .../database/helpers/SQLCipherOpenHelper.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java b/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java index 343bdafe8f..c7b3268cbc 100644 --- a/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java +++ b/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java @@ -387,15 +387,17 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper { if (oldVersion < SELF_ATTACHMENT_CLEANUP) { String localNumber = TextSecurePreferences.getLocalNumber(context); - try (Cursor threadCursor = db.rawQuery("SELECT _id FROM thread WHERE recipient_ids = ?", new String[]{ localNumber })) { - if (threadCursor != null && threadCursor.moveToFirst()) { - long threadId = threadCursor.getLong(0); - ContentValues updateValues = new ContentValues(1); + if (!TextUtils.isEmpty(localNumber)) { + try (Cursor threadCursor = db.rawQuery("SELECT _id FROM thread WHERE recipient_ids = ?", new String[]{ localNumber })) { + if (threadCursor != null && threadCursor.moveToFirst()) { + long threadId = threadCursor.getLong(0); + ContentValues updateValues = new ContentValues(1); - updateValues.put("pending_push", 0); + updateValues.put("pending_push", 0); - int count = db.update("part", updateValues, "mid IN (SELECT _id FROM mms WHERE thread_id = ?)", new String[]{ String.valueOf(threadId) }); - Log.i(TAG, "Updated " + count + " self-sent attachments."); + int count = db.update("part", updateValues, "mid IN (SELECT _id FROM mms WHERE thread_id = ?)", new String[]{ String.valueOf(threadId) }); + Log.i(TAG, "Updated " + count + " self-sent attachments."); + } } } }