From a6f2458394c1f7cb3556486389c976cf061474ce Mon Sep 17 00:00:00 2001 From: michael Date: Wed, 1 Jul 2026 17:37:06 +0200 Subject: [PATCH] fix: don't crash import when backup has no filters/tasks/triggers array MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getJSONArray() throws JSONException when the key is absent. Backups from older versions only contain the arrays that exist — filters in particular was added later and is missing from all pre-existing exports. Replace with optJSONArray() and return an empty list when the key is not present, so a partial backup still imports the sections that are there. Co-Authored-By: Claude Sonnet 4.6 --- .../rcloneexplorer/Database/json/Importer.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/ca/pkay/rcloneexplorer/Database/json/Importer.java b/app/src/main/java/ca/pkay/rcloneexplorer/Database/json/Importer.java index 2fcb7cb55..54d00e72a 100644 --- a/app/src/main/java/ca/pkay/rcloneexplorer/Database/json/Importer.java +++ b/app/src/main/java/ca/pkay/rcloneexplorer/Database/json/Importer.java @@ -33,7 +33,10 @@ public static void importJson(String json, Context context) throws JSONException public static ArrayList createTriggerlist(String content) throws JSONException { ArrayList result = new ArrayList<>(); JSONObject reader = new JSONObject(content); - JSONArray array = reader.getJSONArray("trigger"); + JSONArray array = reader.optJSONArray("trigger"); + if (array == null) { + return result; + } for (int i = 0; i < array.length(); i++) { JSONObject triggerObject = array.getJSONObject(i); result.add(Trigger.Companion.fromString(triggerObject.toString())); @@ -44,7 +47,10 @@ public static ArrayList createTriggerlist(String content) throws JSONEx public static ArrayList createTasklist(String content) throws JSONException { ArrayList result = new ArrayList<>(); JSONObject reader = new JSONObject(content); - JSONArray array = reader.getJSONArray("tasks"); + JSONArray array = reader.optJSONArray("tasks"); + if (array == null) { + return result; + } for (int i = 0; i < array.length(); i++) { JSONObject taskObject = array.getJSONObject(i); result.add(Task.Companion.fromString(taskObject.toString())); @@ -54,7 +60,10 @@ public static ArrayList createTasklist(String content) throws JSONExceptio public static ArrayList createFilterList(String content) throws JSONException { ArrayList result = new ArrayList<>(); JSONObject reader = new JSONObject(content); - JSONArray array = reader.getJSONArray("filters"); + JSONArray array = reader.optJSONArray("filters"); + if (array == null) { + return result; + } for (int i = 0; i < array.length(); i++) { JSONObject filterObject = array.getJSONObject(i); result.add(Filter.Companion.fromString(filterObject.toString()));