Skip to content

SerialDescriptor.getElementIndex can throw #3163

@ansman

Description

@ansman

Describe the bug
The documentation states that SerialDescriptor.getElementIndex returns the index or UNKNOWN_NAME when there is no such element. But the map like descriptor will throw if you pass a non integer like descriptor.

To Reproduce

val serializer = MapSerializer(String.serializer(), String.serializer())
val descriptor = serializer.descriptor
descriptor.getElementIndex("key") // Throws

Expected behavior
There is no documentation that this function will ever throw and it would be more suitable if it returned UNKNOWN_NAME.

Environment

  • Kotlin version: 2.3.10
  • Library version: 1.10.0
  • Kotlin platforms: JVM

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions