Bug 1213240 : Avoid parsing sessions json when empty r=bnicholson
authorvivek <vivekb.balakrishnan@gmail.com>
Thu, 07 Jan 2016 22:42:30 +0200
changeset 320154 a54da7831cfcb3dfb2881573cb84cc058f62368b
parent 320153 3376205bf1d798d8771319fa56a8ef5850f63bc7
child 320155 29b74b9db879bbbd662c38461c10fad3ad22b977
push id9143
push userahunt@mozilla.com
push dateFri, 08 Jan 2016 21:30:53 +0000
reviewersbnicholson
bugs1213240
milestone46.0a1
Bug 1213240 : Avoid parsing sessions json when empty r=bnicholson
mobile/android/base/java/org/mozilla/gecko/SessionParser.java
--- a/mobile/android/base/java/org/mozilla/gecko/SessionParser.java
+++ b/mobile/android/base/java/org/mozilla/gecko/SessionParser.java
@@ -62,17 +62,24 @@ public abstract class SessionParser {
     }
 
     public void parse(String... sessionStrings) {
         final LinkedList<SessionTab> sessionTabs = new LinkedList<SessionTab>();
         int totalCount = 0;
         int selectedIndex = -1;
         try {
             for (String sessionString : sessionStrings) {
-                final JSONObject window = new JSONObject(sessionString).getJSONArray("windows").getJSONObject(0);
+                final JSONArray windowsArray = new JSONObject(sessionString).getJSONArray("windows");
+                if (windowsArray.length() == 0) {
+                    // Session json can be empty if the user has opted out of session restore.
+                    Log.d(LOGTAG, "Session restore file is empty, no session entries found.");
+                    continue;
+                }
+
+                final JSONObject window = windowsArray.getJSONObject(0);
                 final JSONArray tabs = window.getJSONArray("tabs");
                 final int optSelected = window.optInt("selected", -1);
                 final JSONArray closedTabs = window.optJSONArray("closedTabs");
                 if (closedTabs != null) {
                     onClosedTabsRead(closedTabs);
                 }
 
                 for (int i = 0; i < tabs.length(); i++) {