config service: handle fromJson() returning null

Treat it the same as handling a json syntax exception
This commit is contained in:
Adam
2021-01-09 17:05:20 -05:00
parent fa43ca94db
commit 266fee2067
2 changed files with 10 additions and 2 deletions

View File

@@ -233,8 +233,11 @@ public class ConfigService
try
{
jsonValue = RuneLiteAPI.GSON.fromJson(value, Object.class);
if (jsonValue instanceof Double || jsonValue instanceof Float)
if (jsonValue == null)
{
return value;
}
else if (jsonValue instanceof Double || jsonValue instanceof Float)
{
Number number = (Number) jsonValue;
if (Math.floor(number.doubleValue()) == number.doubleValue() && !Double.isInfinite(number.doubleValue()))
@@ -272,6 +275,10 @@ public class ConfigService
{
// I couldn't figure out a better way to do this than a second json parse
JsonElement jsonElement = RuneLiteAPI.GSON.fromJson(value, JsonElement.class);
if (jsonElement == null)
{
return value.length() < MAX_VALUE_LENGTH;
}
return validateObject(jsonElement, 1);
}
catch (JsonSyntaxException ex)

View File

@@ -51,5 +51,6 @@ public class ConfigServiceTest
assertTrue(ConfigService.validateJson("\"test\""));
assertTrue(ConfigService.validateJson("key:value"));
assertTrue(ConfigService.validateJson("{\"key\": \"value\"}"));
assertTrue(ConfigService.validateJson("\n"));
}
}