1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-23 04:41:16 +00:00

Fixed crash when values is read from RestApi before fully initialized (fixes #159).

This commit is contained in:
Felix Ableitner 2014-10-26 02:47:37 +03:00
parent 6bb99f2ae4
commit 84355c2dcf
2 changed files with 10 additions and 6 deletions

View file

@ -69,12 +69,6 @@ public class RestApiTest extends AndroidTestCase {
ConfigXml.getConfigFile(new MockContext(getContext())).delete();
}
@SmallTest
public void testGetVersion() {
assertNotNull(mApi.getVersion());
assertFalse(mApi.getVersion().equals(""));
}
@SmallTest
public void testGetDevices() {
assertNotNull(mApi.getDevices());
@ -151,4 +145,10 @@ public class RestApiTest extends AndroidTestCase {
latch.await(1, TimeUnit.SECONDS);
}
@SmallTest
public void testGetValueEarly() {
// Should never throw an exception.
mApi.getValue("Options", "ListenAddress");
}
}

View file

@ -279,6 +279,10 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener,
* @return The value as a String, or null on failure.
*/
public String getValue(String name, String key) {
// Happens if this functions is called before class is fully initialized.
if (mConfig == null)
return null;
try {
Object value = mConfig.getJSONObject(name).get(key);
return (value instanceof JSONArray)