mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-11-27 04:25:19 +01:00
Fix exception on loading empty file in YamlConfiguration
This commit is contained in:
parent
2262652577
commit
2683bc12c0
@ -183,9 +183,12 @@ public class YamlConfiguration implements IConfiguration, HeaderCommentable, Nod
|
||||
@Override
|
||||
public void load(Reader reader) {
|
||||
Object yamlData = this.yaml.load(reader);
|
||||
if (yamlData == null) {
|
||||
yamlData = Collections.emptyMap();
|
||||
}
|
||||
|
||||
if (!(yamlData instanceof Map)) {
|
||||
throw new IllegalStateException("The YAML file does not have the expected tree structure");
|
||||
throw new IllegalStateException("The YAML file does not have the expected tree structure: " + yamlData.getClass().getName());
|
||||
}
|
||||
|
||||
synchronized (this.values) {
|
||||
|
@ -103,6 +103,16 @@ class YamlConfigurationTest {
|
||||
assertEquals(3, ((List<?>) cfg.get("primitives.set")).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testYamlParserWithEmptyFile() {
|
||||
final YamlConfiguration cfg = new YamlConfiguration();
|
||||
cfg.load(new StringReader(""));
|
||||
assertTrue(cfg.getKeys("").isEmpty());
|
||||
|
||||
cfg.load(new StringReader("\n"));
|
||||
assertTrue(cfg.getKeys("").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testYamlParserWithDuplicateKeys() {
|
||||
assertThrowsExactly(DuplicateKeyException.class,
|
||||
@ -524,7 +534,7 @@ class YamlConfigurationTest {
|
||||
IllegalStateException exception = assertThrowsExactly(IllegalStateException.class,
|
||||
() -> cfg.load(new StringReader("Hello world")));
|
||||
|
||||
assertEquals("The YAML file does not have the expected tree structure", exception.getMessage());
|
||||
assertEquals("The YAML file does not have the expected tree structure: java.lang.String", exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user