Udi Cohen
12/23/2021, 9:14 PM// Java
public @interface InterestingAnnotation {
@interface LevelOfInterest {
boolean forEveryone() default false;
}
LevelOfInterest level() default @LevelOfInterest();
}
// Kotlin
@InterestingAnnotation
class KotlinTestClassKsp {}
In some situations I get a crash from KSP when it tries to retrieve the annotation’s arguments:
Caused by: java.util.NoSuchElementException: Collection is empty.
at kotlin.collections.CollectionsKt___CollectionsKt.single(_Collections.kt:592)
at com.google.devtools.ksp.symbol.impl.binary.KSAnnotationDescriptorImplKt.createKSValueArguments(KSAnnotationDescriptorImpl.kt:149)
at com.google.devtools.ksp.symbol.impl.binary.KSAnnotationDescriptorImpl$arguments$2.invoke(KSAnnotationDescriptorImpl.kt:86)
at com.google.devtools.ksp.symbol.impl.binary.KSAnnotationDescriptorImpl$arguments$2.invoke(KSAnnotationDescriptorImpl.kt:85)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at com.google.devtools.ksp.symbol.impl.binary.KSAnnotationDescriptorImpl.getArguments(KSAnnotationDescriptorImpl.kt:85)
From debugging this, it appears KSP has a problem locating the inner annotation’s constructor (InterestingAnnotation$LevelOfInterest
). I made sure there’s proper dependency to the annotation’s class from both the processor and the code that uses the annotation, still doesn’t work. Since this is not happening for all modules, I do suspect this is a classpath issue, possibly an ABI generation issue. Though, this doesn’t cause problems with KAPT.
Any suggestions on ways to debug this? I can reproduce this in our environment, but couldn’t get a sample code to crash the same way (only similar case - https://github.com/google/ksp/issues/784). Any suggestions for ways to debug this? Maybe there are inner classpath objects inside KSP that could help me see where KSP is looking to find objects.