Bug 1158471 - ASSERTION: selection count is wrong. imap unread message count dump when mismatch occurs. draft
authorISHIKAWA, Chiaki <ishikawa@yk.rim.or.jp>
Mon, 23 May 2022 03:03:50 +0900
changeset 116806 21e6a2b650a718315e63ace1a13a9e3af2589918
parent 116805 573c4b9c4f17a7d418266cf08a54d1af0c2bb22a
child 116807 9d7a99e81cdbd85d83f8aa05390b0a2d589ce3b7
push id15955
push userishikawa@yk.rim.or.jp
push dateSun, 22 May 2022 18:04:18 +0000
treeherdertry-comm-central@beaacca97fbd [default view] [failures only]
bugs1158471
Bug 1158471 - ASSERTION: selection count is wrong. imap unread message count dump when mismatch occurs.
mailnews/base/src/nsMsgDBView.cpp
mailnews/imap/src/nsImapMailFolder.cpp
--- a/mailnews/base/src/nsMsgDBView.cpp
+++ b/mailnews/base/src/nsMsgDBView.cpp
@@ -2392,18 +2392,28 @@ nsMsgDBView::GetIndicesForSelection(nsTA
       if (startRange >= 0 && startRange < viewSize) {
         for (int32_t rangeIndex = startRange;
              rangeIndex <= endRange && rangeIndex < viewSize; rangeIndex++) {
           indices.AppendElement(rangeIndex);
         }
       }
     }
 
-    NS_ASSERTION(indices.Length() == uint32_t(count),
-                 "selection count is wrong");
+    if (indices.Length() != uint32_t(count)) {
+#ifdef DEBUG
+      unsigned long tmp = indices.Length();
+      fprintf(stderr,
+              "(debug): Is selection count wrong? indices.Length() = %lu != "
+              "count =%" PRIi32 "\n",
+              tmp, count);
+#endif
+      NS_ASSERTION(indices.Length() == uint32_t(count),
+                   "selection count is wrong");
+    }
+
   } else {
     // If there is no tree selection object then we must be in stand alone
     // message mode. In that case the selected indices are really just the
     // current message key.
     nsMsgViewIndex viewIndex = FindViewIndex(m_currentlyDisplayedMsgKey);
     if (viewIndex != nsMsgViewIndex_None) indices.AppendElement(viewIndex);
   }
 
--- a/mailnews/imap/src/nsImapMailFolder.cpp
+++ b/mailnews/imap/src/nsImapMailFolder.cpp
@@ -2590,18 +2590,40 @@ NS_IMETHODIMP nsImapMailFolder::UpdateIm
   // hasn't been expunged.
   int32_t previousUnreadMessages =
       (m_numServerUnseenMessages)
           ? m_numServerUnseenMessages
           : mNumPendingUnreadMessages + mNumUnreadMessages;
   if (numUnread != previousUnreadMessages || m_nextUID != prevNextUID) {
     int32_t unreadDelta =
         numUnread - (mNumPendingUnreadMessages + mNumUnreadMessages);
-    if (numUnread - previousUnreadMessages != unreadDelta)
+    if (numUnread - previousUnreadMessages != unreadDelta) {
       NS_WARNING("unread count should match server count");
+#ifdef DEBUG
+      fprintf(stderr, "(debug) count mismatch:\n");
+      fprintf(stderr, "\tnumUnread = %5d, previousUnreadMessages=%5d\n",
+              numUnread, previousUnreadMessages);
+      fprintf(stderr, "\tm_nextUID = %16d, prevNextUID%16d\n", m_nextUID,
+              prevNextUID);
+      fprintf(stderr, "\tm_numServerUnseenMessages=%d\n",
+              m_numServerUnseenMessages);
+      fprintf(stderr, "\tm_NumUnreadMessages=%d\n", mNumUnreadMessages);
+      fprintf(stderr, "\tmNumPendingUnreadMessages=%d\n",
+              mNumPendingUnreadMessages);
+      fprintf(stderr,
+              "\tunreadDelta'= numUnread(%d) - (mNumPendingUnreadMessages(%d) "
+              "+ mNumUnreadMessages(%d))\n",
+              numUnread, mNumPendingUnreadMessages, mNumUnreadMessages);
+
+      fprintf(stderr, "\tnumUnread - previousUnreadMessages = %d\n",
+              numUnread - previousUnreadMessages);
+      fprintf(stderr, "\t != unreadDelta = %d\n", unreadDelta);
+#endif
+    }
+
     ChangeNumPendingUnread(unreadDelta);
     if (unreadDelta > 0 &&
         !(mFlags & (nsMsgFolderFlags::Trash | nsMsgFolderFlags::Junk))) {
       SetHasNewMessages(true);
       SetNumNewMessages(unreadDelta);
       SetBiffState(nsMsgBiffState_NewMail);
     }
     summaryChanged = true;