From aab998d17f5e9817e9da277681b01a6c0bd25f3c Mon Sep 17 00:00:00 2001 From: cketti Date: Fri, 23 Aug 2013 04:13:20 +0200 Subject: [PATCH] Avoid CursorIndexOutOfBoundsException when deleting a message Deleting a message creates an entry in EmailProviderCache so EmailProviderCacheCursor can skip the Cursor row during the time it takes to update the database. Previously EmailProviderCacheCursor.isLast() returned the wrong result when the last row in the wrapped Cursor was hidden. This lead to the crash in MergeCursor. Fixes issue 5820 --- .../fsck/k9/cache/EmailProviderCacheCursor.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/com/fsck/k9/cache/EmailProviderCacheCursor.java b/src/com/fsck/k9/cache/EmailProviderCacheCursor.java index f1ef56fd0..aeb4bdf13 100644 --- a/src/com/fsck/k9/cache/EmailProviderCacheCursor.java +++ b/src/com/fsck/k9/cache/EmailProviderCacheCursor.java @@ -19,6 +19,12 @@ public class EmailProviderCacheCursor extends CursorWrapper { private int mMessageIdColumn; private int mFolderIdColumn; private int mThreadRootColumn; + + /** + * The cursor's current position. + * + * Note: This is only used when {@link #mHiddenRows} isn't empty. + */ private int mPosition; @@ -126,4 +132,13 @@ public class EmailProviderCacheCursor extends CursorWrapper { return mPosition; } + + @Override + public boolean isLast() { + if (mHiddenRows.isEmpty()) { + return super.isLast(); + } + + return (mPosition == getCount() - 1); + } }