Skip to content

Commit 0340a67

Browse files
committed
Handle detached structured config sections
1 parent 6a967ba commit 0340a67

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎SimpleAPI/src/main/java/com/bencodez/simpleapi/bukkit/config/BukkitStructuredConfigView.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ private void collectKeys(Object container, String prefix, boolean deep, Set<Stri
194194
Object value = literal(keys);
195195
if (value instanceof ConfigurationSection section) return sectionView(section);
196196
if (value instanceof Map<?, ?> map) {
197-
return new RawMapView(map, getSection().getRoot().options().pathSeparator());
197+
ConfigurationSection section = getSection();
198+
org.bukkit.configuration.Configuration root = section.getRoot();
199+
return new RawMapView(map, root == null ? '.' : root.options().pathSeparator());
198200
}
199201
return null;
200202
}

‎SimpleAPI/src/test/java/com/bencodez/simpleapi/tests/shared/StructuredConfigViewTest.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.bencodez.simpleapi.tests.shared;
22

33
import static org.junit.jupiter.api.Assertions.*;
4+
import static org.mockito.Mockito.mock;
5+
import static org.mockito.Mockito.when;
46

57
import java.util.ArrayList;
68
import java.util.Arrays;
@@ -133,6 +135,21 @@ class StructuredConfigViewTest {
133135
assertThrows(IllegalArgumentException.class, () -> direct.kindAt("Ambiguous", "10"));
134136
}
135137

138+
@Test void rawMapChildrenRemainUsableWhenTheBukkitSectionHasNoRoot() {
139+
var detached = mock(org.bukkit.configuration.ConfigurationSection.class);
140+
Map<String, Object> child = Map.of("Value", 7);
141+
when(detached.getValues(false)).thenReturn(Map.of("Child", child));
142+
when(detached.getDefaultSection()).thenReturn(null);
143+
when(detached.getRoot()).thenReturn(null);
144+
145+
StructuredConfigView view = new BukkitStructuredConfigView(detached);
146+
StructuredConfigView rawChild = view.structuredAt("Child");
147+
148+
assertNotNull(rawChild);
149+
assertEquals(7, rawChild.getInt("Value", -1));
150+
assertEquals(Map.of("Value", 7), rawChild.valueAt());
151+
}
152+
136153
@Test void deepRawMapKeyEnumerationRejectsCyclesAndExcessiveDepth() {
137154
var nativeConfig = new MemoryConfiguration();
138155
Map<String, Object> cyclic = new LinkedHashMap<>();

0 commit comments

Comments
 (0)