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

NoSuchElementException when getting a default argument of the inner annotation type #989

Closed
popovanton0 opened this issue May 14, 2022 · 0 comments · Fixed by #1099
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@popovanton0
Copy link

popovanton0 commented May 14, 2022

When analyzing a function

@Kira
fun ExampleFunction3(
// ...

annotated with this annotation:

@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
public annotation class Kira(
    val customization: Customization = Customization(enabled = false, supplierImpls = false),
    val targetModule: String = "",
) {
    public annotation class Customization(val enabled: Boolean, val supplierImpls: Boolean)
}

and executing this code in the symbol processor:

val kiraAnn = getAnnotationsByType(Kira::class).first()
kiraAnn.customization

I get the following error:

e: [ksp] 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:151)
	at com.google.devtools.ksp.symbol.impl.binary.KSAnnotationDescriptorImpl$arguments$2.invoke(KSAnnotationDescriptorImpl.kt:88)
	at com.google.devtools.ksp.symbol.impl.binary.KSAnnotationDescriptorImpl$arguments$2.invoke(KSAnnotationDescriptorImpl.kt:87)
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
	at com.google.devtools.ksp.symbol.impl.binary.KSAnnotationDescriptorImpl.getArguments(KSAnnotationDescriptorImpl.kt:87)
	at com.google.devtools.ksp.UtilsKt.createInvocationHandler(utils.kt:350)
	at com.google.devtools.ksp.UtilsKt.asAnnotation(utils.kt:427)
	at com.google.devtools.ksp.UtilsKt.access$asAnnotation(utils.kt:1)
	at com.google.devtools.ksp.UtilsKt$createInvocationHandler$1$value$3.invoke(utils.kt:375)
	at com.google.devtools.ksp.UtilsKt.createInvocationHandler$lambda-8(utils.kt:546)
	at com.sun.proxy.$Proxy33.customization(Unknown Source)
	at com.popovanton0.kira.processing.KiraProcessor.getKiraAnn(KiraProcessor.kt:348)
	at com.popovanton0.kira.processing.KiraProcessor.process(KiraProcessor.kt:20)
	............

However, with this annotation:

@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
public annotation class Kira(
    val customization: Customization = Customization(enabled = false, supplierImpls = false),
    val targetModule: String = "",
)

public annotation class Customization(val enabled: Boolean, val supplierImpls: Boolean)

error does not occur. Seems like a bug. Similar to #784?

ksp version = 1.6.21-1.0.5
kotlin version = 1.6.21

I created a branch in my repo that reproduces this behaviour. To reproduce, run this unit test. Input to the test is here. Code of the processor is here.

@neetopia neetopia self-assigned this May 19, 2022
@neetopia neetopia added the bug Something isn't working label May 19, 2022
@neetopia neetopia added this to the 1.0.7 milestone Jun 9, 2022
neetopia added a commit to neetopia/ksp that referenced this issue Sep 9, 2022
neetopia added a commit to neetopia/ksp that referenced this issue Sep 13, 2022
github-actions bot pushed a commit that referenced this issue Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants