dagger: java.util.NoSuchElementException with Dagger 2.27
Just tried upgrading our app to Dagger 2.27 and removed all JvmStatic annotations and get this internal error in compilation. Dagger expects something to be available but it is not. The error message does not really give any information.
Let me know how I can provide more information. Thanks
> Task app:kaptDebugAndroidTestKotlin FAILED
e: [kapt] An exception occurred: java.util.NoSuchElementException: No value present
at java.util.Optional.get(Optional.java:135)
at dagger.internal.codegen.bindinggraphvalidation.IncompatiblyScopedBindingsValidator.lambda$visitGraph$1(IncompatiblyScopedBindingsValidator.java:74)
at java.util.Optional.ifPresent(Optional.java:159)
at dagger.internal.codegen.bindinggraphvalidation.IncompatiblyScopedBindingsValidator.visitGraph(IncompatiblyScopedBindingsValidator.java:71)
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 1
- Comments: 18 (2 by maintainers)
@0legg @tasomaniac you’ll be happy to know we are indeed currently working on fixing these types of issues so that you get a proper error message.
Part of the fix is improving the error messages for superficial validation (#2208), and the other part is making sure we have sufficient superficial validation for all types before we use them.
This particular issue is due to a lack of superficial validation before using a Module. Stacktraces like in https://github.com/google/dagger/issues/1793#issuecomment-705224100 are super helpful for us to pinpoint where we are missing this validation, but sometimes even with the stacktrace it’s difficult to determine exactly how we got in that state. Thus, even better would be if you could provide a sample project that reproduces the issue, or debug in AndroidStudio/Intellij using the instructions in https://github.com/google/dagger/issues/3090#issuecomment-987593534 to give us more information about the setup that causes this failure. Once we know exactly how we got in this state, we can write a regression test and fix the issue.
I’ve faced the same kind of error as @vRallev (well, in the same codebase) when moving classes from one Gradle module to another. The only change in code structure was making some dependencies of a module
implementationrather thanapi, so some parent components are not visible anymore. Anyway, one way or another, it’s impossible to pinpoint what was the root cause, as even with--stacktracethere are 0 references to our code, only annotation processor, dagger and java internals.I will try to reserve some time soon. Actually what @vRallev mentions is indeed very similar and can be even easier to provide a sample.
@vRallev, yeah the error message is not very helpful in understanding what circumstance led to the error, which unfortunately makes it very difficult for us to repro the error with just a stack trace. This type of error is never meant to be hit by users, and it typically means that an invariant that we’ve assumed in the code has somehow been broken.
It’s very difficult to say until we’ve understood exactly what is causing the issue. In your case, the error message indicates that an element which we thought was a module doesn’t have an
@Moduleannotation, but it’s not obvious how that’s related to your repro description: “A module used in a subcomponent was added to a parent component.” I tried to reproduce this locally, but I couldn’t. If there’s any way you could give a minimal repro example or add more concrete steps to reproduce the error, that would help.