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

View File

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