Fix NPE when loading subject data on Sponge (#1222)

This commit is contained in:
Luck 2018-09-20 10:51:00 +01:00
parent 51b7bb93e2
commit 11a3ecbba0
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 14 additions and 7 deletions

View File

@ -94,14 +94,19 @@ public class SubjectDataContainer {
this.parents = parentsBuilder.build();
}
private SubjectDataContainer(LPPermissionService service, JsonObject root) {
Preconditions.checkArgument(root.get("permissions").isJsonArray());
Preconditions.checkArgument(root.get("options").isJsonArray());
Preconditions.checkArgument(root.get("parents").isJsonArray());
private static JsonArray getArray(JsonObject root, String key) {
JsonElement element = root.get(key);
if (element == null) {
return new JsonArray();
}
Preconditions.checkArgument(element instanceof JsonArray);
return ((JsonArray) element);
}
JsonArray permissions = root.get("permissions").getAsJsonArray();
JsonArray options = root.get("options").getAsJsonArray();
JsonArray parents = root.get("parents").getAsJsonArray();
private SubjectDataContainer(LPPermissionService service, JsonObject root) {
JsonArray permissions = getArray(root, "permissions");
JsonArray options = getArray(root, "options");
JsonArray parents = getArray(root, "parents");
ImmutableMap.Builder<ImmutableContextSet, Map<String, Boolean>> permissionsBuilder = ImmutableMap.builder();
for (JsonElement e : permissions) {

View File

@ -204,6 +204,8 @@ public class SubjectStorage {
JsonObject data = this.gson.fromJson(reader, JsonObject.class);
SubjectDataContainer model = SubjectDataContainer.deserialize(this.service, data);
return new LoadedSubject(subjectName, model);
} catch (Exception e) {
throw new IOException("Exception occurred whilst loading from " + file.toString(), e);
}
}