From 5ef503c3ced36f55464b92b49a34cae2f0d3b778 Mon Sep 17 00:00:00 2001 From: Darcy Wong Date: Tue, 22 Oct 2024 10:06:43 +0700 Subject: [PATCH] fix(android/engine): Increase robustness when handling package kmp.json --- .../com/keyman/engine/packages/JSONUtils.java | 6 + .../keyman/engine/packages/JSONUtilsTest.java | 13 ++ .../invalid_packages/null_languages/kmp.json | 127 ++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 android/KMEA/test_resources/invalid_packages/null_languages/kmp.json diff --git a/android/KMEA/app/src/main/java/com/keyman/engine/packages/JSONUtils.java b/android/KMEA/app/src/main/java/com/keyman/engine/packages/JSONUtils.java index d7645052172..80fa18bc882 100644 --- a/android/KMEA/app/src/main/java/com/keyman/engine/packages/JSONUtils.java +++ b/android/KMEA/app/src/main/java/com/keyman/engine/packages/JSONUtils.java @@ -38,6 +38,9 @@ public static JSONArray getLanguages() { return new JSONArray(); } File[] packages = resourceRoot.listFiles(); + if (packages == null) { + return new JSONArray(); + } JSONArray languagesArray = new JSONArray(); JSONParser parser = new JSONParser(); @@ -60,6 +63,9 @@ public static JSONArray getLanguages() { String kbdFilename = pkg.getName() + "/" + kbdID + ".js"; // Merge languages + if (!kmpKeyboardObj.has("languages")) { + continue; + } JSONArray kmpLanguageArray = kmpKeyboardObj.getJSONArray("languages"); for (int j=0; j