From ae8dc76ba99d8e8c1d5eface190b089b8f662b4b Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 21 Jan 2016 22:08:57 +0100 Subject: [PATCH] Check if JSON string is null before parsing. --- .../nutomic/syncthingandroid/syncthing/RestApi.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java index 3f395e05..960e43bb 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java @@ -218,6 +218,9 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, new GetTask(mHttpsCertPath) { @Override protected void onPostExecute(String s) { + if (s == null) + return; + try { JSONObject json = new JSONObject(s); mVersion = json.getString("version"); @@ -986,11 +989,14 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, /** * Normalizes a given device ID. */ - public void normalizeDeviceId(String id, final OnDeviceIdNormalizedListener listener) { + public void normalizeDeviceId(final String id, final OnDeviceIdNormalizedListener listener) { new GetTask(mHttpsCertPath) { @Override protected void onPostExecute(String s) { super.onPostExecute(s); + if (s == null) + return; + String normalized = null; String error = null; try { @@ -1127,6 +1133,9 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, @Override protected void onPostExecute(String s) { try { + if (s == null) + return; + listener.onReceiveUsageReport(new JSONObject(s).toString(4)); } catch (JSONException e) { throw new RuntimeException("Failed to prettify usage report", e);