KSP: Failed to analyze class
samuelprince007 opened this issue ยท 5 comments
Hi Nicklas! ๐
I seem to hit a bug while migrating from kapt
to ksp
. It seems that having an annotation (java?) on a property e.g @Json
breaks the build with error Kotshi: Failed to analyze class
. When the property annotation is removed, the build compiles without any issues. Interestingly, it seems like kotlin annotations do not produce the same behavior.
For example this will not cause a failure:
annotation class Test(val name: String)
@JsonSerializable
data class MyClass(
@Test(name = "somethingElse")
val someProperty: String
)
While this will cause a failure:
@JsonSerializable
data class MyClass(
@Json(name = "somethingElse")
val someProperty: String
)
Here's the full stacktrace:
java.util.NoSuchElementException: Collection contains no element matching the predicate.
at se.ansman.kotshi.ksp.generators.DataClassAdapterGenerator.toProperty(DataClassAdapterGenerator.kt:125)
at se.ansman.kotshi.ksp.generators.DataClassAdapterGenerator.getGeneratableJsonAdapter(DataClassAdapterGenerator.kt:50)
at se.ansman.kotshi.ksp.generators.AdapterGenerator.generateAdapter(AdapterGenerator.kt:81)
at se.ansman.kotshi.ksp.KotshiSymbolProcessor$generateAdapters$1.invoke(KotshiSymbolProcessor.kt:330)
at se.ansman.kotshi.ksp.KotshiSymbolProcessor$generateAdapters$1.invoke(KotshiSymbolProcessor.kt:278)
at kotlin.sequences.TransformingSequence$iterator$1.next(Sequences.kt:210)
at kotlin.sequences.FilteringSequence$iterator$1.calcNext(Sequences.kt:170)
at kotlin.sequences.FilteringSequence$iterator$1.hasNext(Sequences.kt:194)
at kotlin.sequences.SequencesKt___SequencesKt.toList(_Sequences.kt:816)
at se.ansman.kotshi.ksp.KotshiSymbolProcessor.generateAdapters(KotshiSymbolProcessor.kt:343)
at se.ansman.kotshi.ksp.KotshiSymbolProcessor.process(KotshiSymbolProcessor.kt:232)
at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$8$1.invoke(KotlinSymbolProcessingExtension.kt:305)
at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$8$1.invoke(KotlinSymbolProcessingExtension.kt:303)
at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.handleException(KotlinSymbolProcessingExtension.kt:409)
at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.doAnalysis(KotlinSymbolProcessingExtension.kt:303)
at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:112)
at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:77)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:256)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:247)
at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:115)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:247)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:87)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:43)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:165)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:50)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:104)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:48)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1523)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:577)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:360)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:598)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:844)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:721)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:720)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
So weird, I left a comment a few days ago that's now missing!
What version of Kotshi/Moshi are you using? I tried adding a test case for this and it worked just fine.
No worries ๐ tried it using kotshi - 2.14.0, moshi - 1.8.0
Can you try moshi 1.15?
That worked! I didn't realize how old 1.8.0 was until just now ๐ Interesting that KSP didn't work for 1.8.0 but KAPT did. Anyway, thanks for the help NIcklas! ๐
Good to know, I will investigate to see what went wrong.