Skip to content

Commit 6adb3b8

Browse files
committed
Improve handling of invalid data in json files on bungee
1 parent 45cd3fc commit 6adb3b8

File tree

5 files changed

+30
-17
lines changed

5 files changed

+30
-17
lines changed

SimpleAPI/.classpath

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
3-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
4-
<attributes>
5-
<attribute name="module" value="true"/>
6-
<attribute name="maven.pomderived" value="true"/>
7-
</attributes>
8-
</classpathentry>
93
<classpathentry kind="src" output="target/classes" path="src/main/java">
104
<attributes>
115
<attribute name="optional" value="true"/>
@@ -31,5 +25,16 @@
3125
<attribute name="maven.pomderived" value="true"/>
3226
</attributes>
3327
</classpathentry>
28+
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
29+
<attributes>
30+
<attribute name="maven.pomderived" value="true"/>
31+
<attribute name="optional" value="true"/>
32+
</attributes>
33+
</classpathentry>
34+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
35+
<attributes>
36+
<attribute name="maven.pomderived" value="true"/>
37+
</attributes>
38+
</classpathentry>
3439
<classpathentry kind="output" path="target/classes"/>
3540
</classpath>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
eclipse.preferences.version=1
22
encoding//src/main/java=Cp1252
3+
encoding//src/main/resources=Cp1252
4+
encoding//src/test/java=Cp1252
5+
encoding//src/test/resources=Cp1252
36
encoding/<project>=Cp1252
47
encoding/src=Cp1252
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
eclipse.preferences.version=1
22
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3-
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
44
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5-
org.eclipse.jdt.core.compiler.compliance=17
5+
org.eclipse.jdt.core.compiler.compliance=1.8
66
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
77
org.eclipse.jdt.core.compiler.debug.localVariable=generate
88
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@@ -11,5 +11,5 @@ org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
1111
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
1212
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
1313
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
14-
org.eclipse.jdt.core.compiler.release=disabled
15-
org.eclipse.jdt.core.compiler.source=17
14+
org.eclipse.jdt.core.compiler.release=enabled
15+
org.eclipse.jdt.core.compiler.source=1.8

SimpleAPI/src/main/java/com/bencodez/simpleapi/file/BungeeJsonFile.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,22 +143,20 @@ public List<String> getStringList(String path, List<String> def) {
143143
public List<String> getKeys(String path) {
144144
JsonObject parentNode = navigateToNode(path);
145145
String lastPart = getLastPathPart(path);
146-
JsonObject node = parentNode.getAsJsonObject(lastPart);
146+
JsonObject node = null;
147147
if (path.split("\\.").length == 1) {
148-
node = parentNode;
148+
node = parentNode;
149+
} else if (parentNode != null) {
150+
node = parentNode.getAsJsonObject(lastPart);
149151
}
150-
152+
151153
if (node != null) {
152-
//System.out.println(node.toString());
153154
List<String> keys = new ArrayList<>();
154155
for (Map.Entry<String, JsonElement> entry : node.entrySet()) {
155156
keys.add(entry.getKey());
156157
}
157158
return keys;
158159
}
159-
160-
// System.out.println("getKeys: No valid keys found for path = " + path + ".
161-
// Make sure the path is correct.");
162160
return new ArrayList<>();
163161
}
164162

SimpleAPI/src/test/java/com/bencodez/simpleapi/tests/BungeeJsonFileTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ public void testGetKeysBase() {
109109
assertTrue(keys.contains("two"));
110110
}
111111

112+
@Test
113+
public void testGetKeysInvalidPath() {
114+
List<String> keys = bungeeJsonFile.getKeys("invalid.path");
115+
assertNotNull(keys);
116+
assertTrue(keys.isEmpty());
117+
}
118+
112119
@Test
113120
public void testGetNode() {
114121
bungeeJsonFile.setString("test.node.key", "value");

0 commit comments

Comments
 (0)