Closed ChimpGamer closed 2 years ago
Having the same Issue.
Yes, it is a bug of version 1.8.
It happens only when there are no keys set (only defaults, without any use of set
method).
See the following example. I added a set call to your example.
val yamlFile = YamlFile("test.yml")
yamlFile.createOrLoad()
yamlFile.addDefault("default", "test")
yamlFile.set("key", 0)
yamlFile.save()
test.yml
default: test
key: 0
Reopen until the 1.8.1 release
Workaround for 1.8:
fun addDefault(yamlFile: YamlFile, path: String, value: Any) {
if (!yamlFile.isSet(path)) {
yamlFile.set(path, value)
}
yamlFile.addDefault(path, value)
}
fun main() {
val yamlFile = YamlFile("test.yml")
yamlFile.createOrLoad()
addDefault(yamlFile, "default", "test")
yamlFile.save()
}
default: test
I noticed that since the 1.8 update that addDefault doesn't work any more since the test.yml is empty after being created and saved. I was able to recreate this in a test project which I uploaded to github: https://github.com/ChimpGamer/SimpleYamlBug/blob/main/src/main/kotlin/nl/chimpgamer/simpleyamlbug/Main.kt
Am I missing something or is it really a bug?