question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NoSuchElementException when getting annotation arguments from FB's infer

See original GitHub issue

If we declare a dependency on FB’s Infer:

api("com.facebook.infer.annotation:infer-annotation:0.18.0")

And declare a class using an Infer annotations:

import com.facebook.infer.annotation.Nullsafe;

@Nullsafe(Nullsafe.Mode.STRICT)
public interface D {
}

And we try to get the information about the annotation used in the KSP processor:

(resolver
  .getClassDeclarationByName("com.example.D")!!
  .annotations.first().arguments[1].value!! as KSAnnotation)
  .arguments

We get a NoSuchElementException rather than the Set we expect:

[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 TestProcessor.process(TestProcessor.kt:24)

Kotlin version 1.6.10 KSP version 1.6.10-1.0.4

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
amandeepgcommented, Mar 20, 2022

Thanks, a sample project would be great

playground2.zip

$ ./gradlew :workload:kspKotlin

> Task :workload:kspKotlin FAILED
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 TestProcessor.process(TestProcessor.kt:14)
0reactions
mabdelfattahmcommented, May 13, 2022

I am having the same issue using kotlinx.serialization annotations. Classes annotated with @Serialized is producing the same error stack trace

[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)
Read more comments on GitHub >

github_iconTop Results From Across the Web

NoSuchElementException when getting a default argument of ...
I get the following error: e: [ksp] java.util.NoSuchElementException: Collection is empty. at kotlin.collections.
Read more >
Bug List - Bugs - Eclipse
... NEW, ---, Java file, which is generated by annotation processor, is not compiled, 11:34:30 ... [infer type arguments] - StackOverflowError, 2022-09-03.
Read more >
[Example code]-scrape the anglelist data - appsloveworld.com
I want to print the name of company list but it print nothing. score:-1. Accepted answer. import requests from selenium import webdriver from...
Read more >
Untitled
Harry potter 2001 movie, Age of empires 3 how to get boneguard, Newmarket soccer centre ... Tomcat5.exe command line parameters, Hauschka or gano...
Read more >
topAbbWordPair.txt - GitHub
... val value 31645 ns namespace 31474 a annotation 31335 gbc gridbagconstraints ... 3176 s sparse 3174 a argument 3173 str stream 3172...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found