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

Compiling annotation that does not exist throws NoSuchElementException #881

Open
agrosner opened this issue Feb 21, 2024 · 2 comments
Open
Labels
bug Something isn't working

Comments

@agrosner
Copy link

agrosner commented Feb 21, 2024

in 2.5.0-beta1, kotlin 1.9.22

I have an annotation in code that was mistakenly using old package name from a merge conflict. I tried compiling the app and anvil crushes the compilation error:

import com.foo.wrong.Bar // does not actually exist anymore

@Bar
class MyClass

Anvil fails with:

e: java.util.NoSuchElementException: Collection contains no element matching the predicate.
at com.squareup.anvil.compiler.internal.PsiUtilsKt.requireFqName(PsiUtils.kt:379)
at com.squareup.anvil.compiler.internal.PsiUtilsKt.requireFqName(PsiUtils.kt:136)
at com.squareup.anvil.compiler.internal.PsiUtilsKt.requireFqName(PsiUtils.kt:154)
at com.squareup.anvil.compiler.internal.reference.AnnotationReferenceKt.toAnnotationReference(AnnotationReference.kt:227)
at com.squareup.anvil.compiler.internal.reference.ClassReference$Psi$annotations$2.invoke(ClassReference.kt:156)
at com.squareup.anvil.compiler.internal.reference.ClassReference$Psi$annotations$2.invoke(ClassReference.kt:155)
at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:81)
at com.squareup.anvil.compiler.internal.reference.ClassReference$Psi.getAnnotations(ClassReference.kt:155)
at com.squareup.anvil.compiler.internal.reference.AnnotatedReference$DefaultImpls.isAnnotatedWith(AnnotatedReference.kt:14)
at com.squareup.anvil.compiler.internal.reference.ClassReference.isAnnotatedWith(ClassReference.kt:54)
at com.squareup.anvil.compiler.codegen.BindingModuleGenerator.generateCode(BindingModuleGenerator.kt:74)
at com.squareup.anvil.compiler.codegen.CodeGenerationExtension.generateCode$generateCode(CodeGenerationExtension.kt:193)
at com.squareup.anvil.compiler.codegen.CodeGenerationExtension.generateCode(CodeGenerationExtension.kt:219)

@RBusarow
Copy link
Member

As I understand it, you fixed the issue in your code but Anvil is still trying to reference the old type name?

This sounds like a symptom of the incremental compilation issues that were addressed in the current beta release.

In order to enable the new behavior, you need to enable the trackSourceFiles flag in the Gradle extension or in gradle.properties via com.squareup.anvil.trackSourceFiles=true.

@agrosner
Copy link
Author

Sorry to clarify, we have that already turned on. This is code from a stale branch merged from the main branch. The merged code referenced an annotation that moved packages but the code was not updated to use it. So hitting compile resulted in the error above.

@RBusarow RBusarow added the bug Something isn't working label Feb 26, 2024
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

No branches or pull requests

2 participants