Merge "catch some cases of reading a closed MessageCursor" into jb-ub-mail
diff --git a/src/com/android/mail/ui/AbstractConversationViewFragment.java b/src/com/android/mail/ui/AbstractConversationViewFragment.java
index ead310a..1e096af 100644
--- a/src/com/android/mail/ui/AbstractConversationViewFragment.java
+++ b/src/com/android/mail/ui/AbstractConversationViewFragment.java
@@ -467,11 +467,20 @@
                         LogUtils.i(LOG_TAG, "CVF: offscreen conv has no messages, ignoring update"
                                 + " in anticipation of conv cursor update. c=%s", mConversation.uri);
                     }
+                    // existing mCursor will imminently be closed, must stop referencing it
+                    // since we expect to be kicked out soon, it doesn't matter what mCursor
+                    // becomes
+                    mCursor = null;
                     return;
                 }
 
                 // ignore cursors that are still loading results
                 if (!messageCursor.isLoaded()) {
+                    // existing mCursor will imminently be closed, must stop referencing it
+                    // in this case, the new cursor is also no good, and since don't expect to get
+                    // here except in initial load situations, it's safest to just ensure the
+                    // reference is null
+                    mCursor = null;
                     return;
                 }
                 final MessageCursor oldCursor = mCursor;
diff --git a/src/com/android/mail/ui/ConversationViewFragment.java b/src/com/android/mail/ui/ConversationViewFragment.java
index a6e5307..7af88cd 100644
--- a/src/com/android/mail/ui/ConversationViewFragment.java
+++ b/src/com/android/mail/ui/ConversationViewFragment.java
@@ -1106,10 +1106,8 @@
          * similar to #1) 6. other label change Use MessageCursor.hashCode() to
          * sort out interesting vs. no-op cursor updates.
          */
-        final boolean changed = newCursor != null && oldCursor != null
-                && newCursor.getStateHashCode() != oldCursor.getStateHashCode();
 
-        if (oldCursor != null) {
+        if (oldCursor != null && !oldCursor.isClosed()) {
             final NewMessagesInfo info = getNewIncomingMessagesInfo(newCursor);
 
             if (info.count > 0) {
@@ -1122,6 +1120,9 @@
                 return;
             }
 
+            final boolean changed = newCursor != null &&
+                    newCursor.getStateHashCode() != oldCursor.getStateHashCode();
+
             if (!changed) {
                 final boolean processedInPlace = processInPlaceUpdates(newCursor, oldCursor);
                 if (processedInPlace) {