Some nullability in InceptumConfig

This commit is contained in:
Johannes Frohnmeyer 2022-09-18 19:48:12 +02:00
parent 67bb89abe7
commit 58ffd7d11e
Signed by: Johannes
GPG Key ID: E76429612C2929F4
1 changed files with 11 additions and 2 deletions

View File

@ -42,8 +42,8 @@ public class InceptumConfig {
case "snapshots" -> snapshots = jr.nextBoolean();
case "darkTheme" -> darkTheme = jr.nextBoolean();
case "enforceAccount" -> enforceAccount = jr.nextBoolean();
case "lastAccount" -> lastAccount = jr.nextString();
case "offlineAccountLastName" -> offlineAccountLastName = jr.nextString();
case "lastAccount" -> lastAccount = nullableString(jr);
case "offlineAccountLastName" -> offlineAccountLastName = nullableString(jr);
case "channel" -> {
try {
channel = UpdateChannel.valueOf(jr.nextString());
@ -60,6 +60,7 @@ public class InceptumConfig {
} catch (Throwable t) {
if (name == null) Utils.LOGGER.error("Could not read config entry", t);
else Utils.LOGGER.error("Could not read config entry: " + name, t);
return;
}
}
jr.endObject();
@ -93,4 +94,12 @@ public class InceptumConfig {
Utils.LOGGER.error("Could not save config", e);
}
}
private static String nullableString(JsonReader jr) throws IOException {
if (jr.peek() == JsonToken.NULL) {
jr.nextNull();
return null;
}
return jr.nextString();
}
}