aboutsummaryrefslogtreecommitdiff
path: root/spark-common/src
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2022-05-06 19:22:46 +0100
committerLuck <git@lucko.me>2022-05-06 19:22:46 +0100
commit49b8f5330ad8bf0b7203d507c356028014170b98 (patch)
treec4e8294d297e99da1fc40619c82f5491ca6bb7bb /spark-common/src
parentd61469c0b2a356a886404cbf22767ef07048facf (diff)
downloadspark-49b8f5330ad8bf0b7203d507c356028014170b98.tar.gz
spark-49b8f5330ad8bf0b7203d507c356028014170b98.tar.bz2
spark-49b8f5330ad8bf0b7203d507c356028014170b98.zip
Fix NPE in config provider delete method (#199)
Diffstat (limited to 'spark-common/src')
-rw-r--r--spark-common/src/main/java/me/lucko/spark/common/platform/serverconfig/AbstractServerConfigProvider.java25
1 files changed, 21 insertions, 4 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/platform/serverconfig/AbstractServerConfigProvider.java b/spark-common/src/main/java/me/lucko/spark/common/platform/serverconfig/AbstractServerConfigProvider.java
index d09eb7c..56b3731 100644
--- a/spark-common/src/main/java/me/lucko/spark/common/platform/serverconfig/AbstractServerConfigProvider.java
+++ b/spark-common/src/main/java/me/lucko/spark/common/platform/serverconfig/AbstractServerConfigProvider.java
@@ -27,9 +27,11 @@ import com.google.gson.JsonObject;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Map;
+import java.util.stream.Collectors;
/**
* Abstract implementation of {@link ServerConfigProvider}.
@@ -99,13 +101,28 @@ public abstract class AbstractServerConfigProvider<T extends Enum<T>> implements
}
JsonObject jsonObject = json.getAsJsonObject();
- String member = path.removeFirst().replace("<dot>", ".");
+ String expected = path.removeFirst().replace("<dot>", ".");
- if (member.equals("*") || jsonObject.has(member)) {
+ Collection<String> keys;
+ if (expected.equals("*")) {
+ keys = jsonObject.entrySet().stream()
+ .map(Map.Entry::getKey)
+ .collect(Collectors.toList());
+ } else if (jsonObject.has(expected)) {
+ keys = Collections.singletonList(expected);
+ } else {
+ keys = Collections.emptyList();
+ }
+
+ for (String key : keys) {
if (path.isEmpty()) {
- jsonObject.remove(member);
+ jsonObject.remove(key);
} else {
- delete(jsonObject.get(member), path);
+ Deque<String> pathCopy = expected.equals("*")
+ ? new LinkedList<>(path)
+ : path;
+
+ delete(jsonObject.get(key), pathCopy);
}
}
}