diff --git a/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/RestApiTest.java b/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/RestApiTest.java index a774047e..f9dd0a4f 100644 --- a/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/RestApiTest.java +++ b/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/RestApiTest.java @@ -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"); + } + } diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java index e7e7e95c..b72928eb 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java @@ -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)