Bug 1213240 : Avoid parsing sessions json when empty r?bnicholson
--- 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++) {