Skip to content

Hcon: error while trying to decode MAP #1046

@SchweinchenFuntik

Description

@SchweinchenFuntik

Describe the bug

bug.conf

value1 {
    name = "name1",
    dir = "dir1"
    fileExtension = ".xlsx"
}

value2 {
    name = "name2",
    dir = "dir2"
    fileExtension = ".xlsx"
}

value3 {
    name = "name3",
    dir = "dir3"
    fileExtension = ".xlsx"
}

code

@Serializable
data class TestConfig(
    val name: String,
    val dir: String = "",
    val fileExtension: String = ".xlsx",
)

@ExperimentalSerializationApi
fun main() {
    val bugConfig = Files.newBufferedReader(Path.of("./bug.conf")).use(ConfigFactory::parseReader)
    val bugMap = Server.hoconParser.decodeFromConfig<Map<String, TestConfig>>(bugConfig)
}

Exception

Exception in thread "main" java.util.NoSuchElementException: List is empty.
	at kotlin.collections.CollectionsKt___CollectionsKt.last(_Collections.kt:380)
	at kotlinx.serialization.internal.TaggedDecoder.getCurrentTag(Tagged.kt:308)
	at kotlinx.serialization.hocon.Hocon$ConfigReader.beginStructure(Hocon.kt:138)
	at kotlinx.serialization.internal.AbstractCollectionSerializer.merge(CollectionSerializers.kt:29)
	at kotlinx.serialization.internal.AbstractCollectionSerializer.deserialize(CollectionSerializers.kt:43)
	at kotlinx.serialization.encoding.Decoder$DefaultImpls.decodeSerializableValue(Decoding.kt:243)
	at kotlinx.serialization.internal.TaggedDecoder.decodeSerializableValue(Tagged.kt:179)
	at kotlinx.serialization.hocon.Hocon.decodeFromConfig(Hocon.kt:34)
	at TestKt.main(test.kt:194)
	at TestKt.main(test.kt)

error in code https://github.com/Kotlin/kotlinx.serialization/blob/master/formats/hocon/src/main/kotlin/kotlinx/serialization/hocon/Hocon.kt#L138:

descriptor.kind == StructureKind.MAP -> MapConfigReader(conf.getObject(currentTag)) // currentTag NULL, tagStack: size 0

Environment

  • Kotlin version: 1.4.0
  • Library version: 1.0.0-RC
  • Kotlin platforms: JVM
  • Gradle version: 6.6.1

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions