Bug 1262600 - crash in java.lang.IndexOutOfBoundsException: Invalid index -1, size is 13 at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java). r=sebastian draft
authorChenxia Liu <liuche@mozilla.com>
Thu, 07 Apr 2016 15:14:54 -0700
changeset 348691 4c06f3ecc0879d688ae63f5da8564cc88e8371f5
parent 348188 fbf998f960c7d4c5f44b52f2dd5473a0257cf351
child 517903 0b7cd7d9b22763d22e381f2e13615337daeba400
push id14884
push usercliu@mozilla.com
push dateThu, 07 Apr 2016 22:15:08 +0000
reviewerssebastian
bugs1262600
milestone48.0a1
Bug 1262600 - crash in java.lang.IndexOutOfBoundsException: Invalid index -1, size is 13 at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java). r=sebastian MozReview-Commit-ID: 4H8fqxaR9mO
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryAdapter.java
@@ -117,17 +117,17 @@ public class CombinedHistoryAdapter exte
 
                 sState.setClientHidden(client.guid, true);
                 hiddenClients.add(client);
                 if (!hadHiddenClients) {
                     // Add item for unhiding clients;
                     remoteClients.add(null);
                 } else {
                     // Update "hidden clients" item because number of hidden clients changed.
-                    notifyItemChanged(getRemoteClientsHiddenItemsIndex());
+                    notifyItemChanged(remoteClients.size() - 1);
                 }
                 break;
             case HISTORY:
                 notifyItemRemoved(position);
                 break;
         }
     }
 
@@ -136,46 +136,30 @@ public class CombinedHistoryAdapter exte
             return;
         }
 
         for (RemoteClient client : selectedClients) {
             sState.setClientHidden(client.guid, false);
             hiddenClients.remove(client);
         }
 
-        final int insertIndex = getRemoteClientsHiddenItemsIndex();
+        final int insertIndex = remoteClients.size() - 1;
 
         remoteClients.addAll(insertIndex, selectedClients);
         notifyItemRangeInserted(insertIndex, selectedClients.size());
 
         if (hiddenClients.isEmpty()) {
             // No more hidden clients, remove "unhide" item.
-            remoteClients.remove(getRemoteClientsHiddenItemsIndex());
+            remoteClients.remove(remoteClients.size() - 1);
         } else {
             // Update "hidden clients" item because number of hidden clients changed.
-            notifyItemChanged(getRemoteClientsHiddenItemsIndex());
+            notifyItemChanged(remoteClients.size() - 1);
         }
     }
 
-    /**
-     * Get the position of the "N devices hidden" item in the remoteClients List.
-     *
-     * This is the last item in the remoteClients list, if any items are hidden.
-     * <code>hiddenClients</code> must be in a consistent state with <code>remoteClients</code>
-     * (e.g. each client should be in exactly one of the two lists).
-     *
-     * @return index of the "N devices hidden" item, or -1 if it doesn't exist.
-     */
-    private int getRemoteClientsHiddenItemsIndex() {
-        if (hiddenClients.isEmpty()) {
-            return -1;
-        }
-        return remoteClients.size() - 1;
-    }
-
     public List<RemoteClient> getHiddenClients() {
         return hiddenClients;
     }
 
     public JSONArray getCurrentChildTabs() {
         if (clientChildren != null) {
             final JSONArray urls = new JSONArray();
             for (int i = 1; i < clientChildren.size(); i++) {