Open
Description
I was using MoshiX-KSP, and accidentally attempted to codegen a JsonAdapter for a class that had no declared package:
//in Envelope.kt
import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true)
class EnvelopedResponse<T>(
val message: String? = null,
val data: T? = null,
)
This caused the following stacktrace:
e: [ksp] Error preparing EnvelopedResponse: com.squareup.kotlinpoet.UtilKt.failIfEscapeInvalid(Util.kt:261)
com.squareup.kotlinpoet.UtilKt.escapeIfNecessary(Util.kt:270)
com.squareup.kotlinpoet.UtilKt.escapeIfNecessary$default(Util.kt:267)
com.squareup.kotlinpoet.UtilKt$escapeSegmentsIfNecessary$2.invoke(Util.kt:293)
com.squareup.kotlinpoet.UtilKt$escapeSegmentsIfNecessary$2.invoke(Util.kt)
kotlin.text.StringsKt__AppendableKt.appendElement(Appendable.kt:85)
kotlin.collections.CollectionsKt___CollectionsKt.joinTo(_Collections.kt:3324)
kotlin.collections.CollectionsKt___CollectionsKt.joinToString(_Collections.kt:3341)
kotlin.collections.CollectionsKt___CollectionsKt.joinToString$default(_Collections.kt:3340)
com.squareup.kotlinpoet.UtilKt.escapeSegmentsIfNecessary(Util.kt:293)
com.squareup.kotlinpoet.UtilKt.escapeSegmentsIfNecessary$default(Util.kt:291)
com.squareup.kotlinpoet.ClassName.emit$kotlinpoet(TypeName.kt:449)
com.squareup.kotlinpoet.TypeName$cachedString$2.invoke(TypeName.kt:81)
com.squareup.kotlinpoet.TypeName$cachedString$2.invoke(TypeName.kt:70)
kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
com.squareup.kotlinpoet.TypeName.getCachedString(TypeName.kt)
com.squareup.kotlinpoet.TypeName.toString(TypeName.kt:110)
com.squareup.kotlinpoet.TypeName.hashCode(TypeName.kt:108)
dev.zacsweers.moshix.ksp.shade.api.DelegateKey.hashCode(DelegateKey.kt)
java.base/java.util.HashMap.hash(HashMap.java:340)
java.base/java.util.HashMap.put(HashMap.java:612)
java.base/java.util.HashSet.add(HashSet.java:221)
dev.zacsweers.moshix.ksp.shade.api.AdapterGenerator.generateType(AdapterGenerator.kt:795)
dev.zacsweers.moshix.ksp.shade.api.AdapterGenerator.prepare(AdapterGenerator.kt:178)
dev.zacsweers.moshix.ksp.JsonClassSymbolProcessor.process(JsonClassSymbolProcessor.kt:121)
com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$$inlined$forEach$lambda$2.invoke(KotlinSymbolProcessingExtension.kt:151)
com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$$inlined$forEach$lambda$2.invoke(KotlinSymbolProcessingExtension.kt:71)
com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.handleException(KotlinSymbolProcessingExtension.kt:228)
com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.doAnalysis(KotlinSymbolProcessingExtension.kt:150)
org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:116)
Adding the package
statement fixed it (and it should have been there anyway), so I suspect this is just an edge case in KotlinPoet's escaping system?
This issue was originally filed in MoshiX: ZacSweers/MoshiX#104
Activity