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

Generating ProtoBuf schema using UInt fails #2089

Closed
alexvas opened this issue Nov 7, 2022 · 1 comment · Fixed by #2542
Closed

Generating ProtoBuf schema using UInt fails #2089

alexvas opened this issue Nov 7, 2022 · 1 comment · Fixed by #2542
Assignees
Labels

Comments

@alexvas
Copy link

alexvas commented Nov 7, 2022

Unable to generate ProtoBuf schema from a data class containing UInt field. The error is:

Exception in thread "main" java.lang.IllegalArgumentException: Invalid name of the field '[UNINITIALIZED]' in message 'UInt' for class with serial name 'kotlin.UInt'
	at kotlinx.serialization.protobuf.schema.ProtoBufSchemaGenerator.checkIsValidIdentifier(ProtoBufSchemaGenerator.kt:538)
	at kotlinx.serialization.protobuf.schema.ProtoBufSchemaGenerator.generateMessage(ProtoBufSchemaGenerator.kt:172)
	at kotlinx.serialization.protobuf.schema.ProtoBufSchemaGenerator.generateProto2SchemaText(ProtoBufSchemaGenerator.kt:132)
	at kotlinx.serialization.protobuf.schema.ProtoBufSchemaGenerator.generateSchemaText(ProtoBufSchemaGenerator.kt:84)
	at kotlinx.serialization.protobuf.schema.ProtoBufSchemaGenerator.generateSchemaText$default(ProtoBufSchemaGenerator.kt:76)
	at mypackage.ProtocolGeneratorKt.main(ProtocolGenerator.kt:14)
	at mypackage.ProtocolGeneratorKt.main(ProtocolGenerator.kt)

To Reproduce

package mypackage

import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.Serializable
import kotlinx.serialization.protobuf.schema.ProtoBufSchemaGenerator

@Serializable
data class Wrapper(
    val f: UInt,
)

@OptIn(ExperimentalSerializationApi::class)
fun main() {
    val schemas = ProtoBufSchemaGenerator.generateSchemaText(listOf(Wrapper.serializer().descriptor))
    println(schemas)
}

Expected behavior
Schema generated OK. Indeed this is the case after e.g. substitution of UInt with Long. Which is not desired.

Environment

  • Kotlin version: 1.7.10
  • Library version: 1.4.1
  • Kotlin platforms: JVM
@shanshin shanshin self-assigned this Nov 8, 2022
@shanshin shanshin added the bug label Nov 8, 2022
@rotilho
Copy link
Contributor

rotilho commented Jan 7, 2024

Same issue but for UShort. I checked the other unsigned types and they are all failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants