Fixed NPE when JSON parsing fails.

This commit is contained in:
Felix Ableitner 2015-03-14 21:19:27 +01:00
parent a3b7241c1e
commit 96a266e7fd
1 changed files with 3 additions and 3 deletions

View File

@ -282,7 +282,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
public String getValue(String name, String key) { public String getValue(String name, String key) {
// Happens if this functions is called before class is fully initialized. // Happens if this functions is called before class is fully initialized.
if (mConfig == null) if (mConfig == null)
return null; return "";
try { try {
Object value = mConfig.getJSONObject(name).get(key); Object value = mConfig.getJSONObject(name).get(key);
@ -291,7 +291,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
: value.toString(); : value.toString();
} catch (JSONException e) { } catch (JSONException e) {
Log.w(TAG, "Failed to get value for " + key, e); Log.w(TAG, "Failed to get value for " + key, e);
return null; return "";
} }
} }
@ -416,7 +416,7 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
return ret; return ret;
} catch (JSONException e) { } catch (JSONException e) {
Log.w(TAG, "Failed to read devices", e); Log.w(TAG, "Failed to read devices", e);
return null; return new ArrayList<>();
} }
} }