Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Descriptor of external serializer is incomplete #2549

Open
TheMrMilchmann opened this issue Jan 22, 2024 · 0 comments
Open

Descriptor of external serializer is incomplete #2549

TheMrMilchmann opened this issue Jan 22, 2024 · 0 comments

Comments

@TheMrMilchmann
Copy link
Contributor

Describe the bug
An external serializer's descriptor seems to lack element descriptors despite having elements. This leads to unexpected errors and currently prevents me from implementing some complex custom serializers, including a shape-agnostic solution for #292.

To Reproduce
Consider the following simple test program:

@Serializer(forClass = Foo::class)
object GeneratedFooSerializer : KSerializer<Foo>

@Serializable
data class Foo(val bar: String)

fun main() {
    println(GeneratedFooSerializer.descriptor)
}

This will throw an AIOOB:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
	at kotlinx.serialization.internal.PluginGeneratedSerialDescriptor.getElementDescriptor(PluginGeneratedSerialDescriptor.kt:135)
	at kotlinx.serialization.internal.PluginGeneratedSerialDescriptor$toString$1.invoke(PluginGeneratedSerialDescriptor.kt:101)
	at kotlinx.serialization.internal.PluginGeneratedSerialDescriptor$toString$1.invoke(PluginGeneratedSerialDescriptor.kt:100)
	at kotlin.text.StringsKt__AppendableKt.appendElement(Appendable.kt:85)
	at kotlin.collections.CollectionsKt___CollectionsKt.joinTo(_Collections.kt:3490)
	at kotlin.collections.CollectionsKt___CollectionsKt.joinToString(_Collections.kt:3507)
	at kotlin.collections.CollectionsKt___CollectionsKt.joinToString$default(_Collections.kt:3506)
	at kotlinx.serialization.internal.PluginGeneratedSerialDescriptor.toString(PluginGeneratedSerialDescriptor.kt:100)
	at java.base/java.lang.String.valueOf(String.java:4461)
	at java.base/java.io.PrintStream.println(PrintStream.java:1187)
	at TestKt.main(Test.kt:33)
	at TestKt.main(Test.kt)

Expected behavior
Checking elementsCountconfirms that there is one element. getElementName and getElementAnnotations work fine but getElementDescriptor throws. I expect this to work fine as all required information should be available.

Environment

  • Kotlin version: 1.9.22
  • Library version: 1.6.2
  • Kotlin platforms: any
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants