mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-12-23 03:11:30 +00:00
Fixed crash when values is read from RestApi before fully initialized (fixes #159).
This commit is contained in:
parent
6bb99f2ae4
commit
84355c2dcf
2 changed files with 10 additions and 6 deletions
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue