I have a problem migrating to KSP2. It looks like ...
# ksp
r
I have a problem migrating to KSP2. It looks like https://github.com/google/ksp/issues/1998 but I'm on
2.1.20-RC-1.0.30
.
The exception is thrown when I try to read a parameter of an annotation on a class, which has a default value. The annotation is defined like this:
Copy code
@Target(AnnotationTarget.CLASS)
public annotation class SimpleHtmlComponent(val tagName: String, val withText: Boolean = false)
I'm reading it with this code:
Copy code
val simpleHtmlComponent = classDeclaration.getAnnotationsByType(SimpleHtmlComponent::class).first()
val tagName = simpleHtmlComponent.tagName
val withText = simpleHtmlComponent.withText
The last line throws the exception:
Copy code
java.util.NoSuchElementException: Collection contains no element matching the predicate.
        at com.google.devtools.ksp.UtilsKt.createInvocationHandler$lambda$8(utils.kt:587)
        at jdk.proxy44/jdk.proxy44.$Proxy315.withText(Unknown Source)
        at dev.kilua.ksp.KiluaProcessor.process(KiluaProcessor.kt:62)
        at com.google.devtools.ksp.impl.KotlinSymbolProcessing$execute$1$1.invoke(KotlinSymbolProcessing.kt:581)
        at com.google.devtools.ksp.impl.KotlinSymbolProcessing$execute$1$1.invoke(KotlinSymbolProcessing.kt:579)
        at ksp.com.google.devtools.ksp.common.IncrementalContextBase.closeFilesOnException(IncrementalContextBase.kt:404)
        at com.google.devtools.ksp.impl.KotlinSymbolProcessing.execute(KotlinSymbolProcessing.kt:579)
        at com.google.devtools.ksp.impl.KSPLoader$Companion.loadAndRunKSP(KSPLoader.kt:37)
        at com.google.devtools.ksp.impl.KSPLoader.loadAndRunKSP(KSPLoader.kt)
Am I doing something wrong or is this a bug?
t
It's hard to say, but if it is working in KSP1 but not KSP2, please feel free to create an issue and share a reproducible case. It looks to me that it failed to find the corresponding argument for
.withText
in the proxy. That probably has something to do with the default argument assuming that it is fine with
.tagName
one line above. I can't really tell what exactly happened without diving into a concrete example though.
r