From 404edf8cab6b2284b88b24bc37c0b97616a97c74 Mon Sep 17 00:00:00 2001 From: cketti Date: Sun, 1 Nov 2020 15:04:34 +0100 Subject: [PATCH] Don't crash when MessageListLoader couldn't retrieve any Cursors --- .../com/fsck/k9/ui/messagelist/MessageListLoader.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLoader.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLoader.kt index bbb06c667..5559dde7d 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLoader.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLoader.kt @@ -45,14 +45,19 @@ class MessageListLoader( .mapNotNull { loadMessageListForAccount(it, config) } .toTypedArray() + if (cursors.isEmpty()) { + Timber.w("Couldn't get message list") + return MessageListInfo(messageListItems = emptyList(), hasMoreMessages = false) + } + val cursor: Cursor val uniqueIdColumn: Int - if (cursors.size > 1) { - cursor = MergeCursorWithUniqueId(cursors, getComparator(config)) - uniqueIdColumn = cursor.getColumnIndex("_id") - } else { + if (cursors.size == 1) { cursor = cursors[0] uniqueIdColumn = MLFProjectionInfo.ID_COLUMN + } else { + cursor = MergeCursorWithUniqueId(cursors, getComparator(config)) + uniqueIdColumn = cursor.getColumnIndex("_id") } val messageListItems = cursor.use {