-
Notifications
You must be signed in to change notification settings - Fork 2k
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
java.util.NoSuchElementException with Dagger 2.27 #1793
Comments
It is also reproducible with 2.26 |
The error is occurring on the incompatible scope validator, when a binding has a scope that the component does not have. I wish Dagger had a processor option that logs elements being visited so that tracing when a failure happens is easier. Anyway, you can get us more information by attaching a debugger into the Dagger compiler. For kapt you can do this with a command like:
Then in the IDE add a new run configuration of the 'Remote' category and when the command above start click the 'attach debug' icon. There are more instructions (with screenshots) in this comment. A breakpoint inside the for-each in |
Thanks for the detailed reply. I will try that. Should this be caught earlier to signal a proper error message? Or is it not possible? |
Sorry, I think I wasn't very clear, the error you are seeing is occurring during the incompatible scope validation, but does not mean that the actual error is an invalid scope. Instead a failing assertion expectation is occurring in the processor, an optional that is always suppose to be present is not, basically a NPE. If you can find more information we can figure out if it was something we can error out earlier of its really a processor issue, a missed case of some sort. [Edit]: Specifically if you can find the location in your source code that is causing the issue and share the code with us then that would be very helpful. |
Understood 👍 that makes sense. I'm doing this now. Which properties/fields should I be looking at to find "elements being visited" |
Ok, I got it. So this is happening on connected It looks like this.
The app builds fine btw and has the following
We put
Edit: Actually |
Here is where the comparison fails:
I guess while building
|
Any chance that you can have a look into this? This is blocking for us to upgrade our Dagger version. |
We recently ran into this issue, too. The error message is not helpful at all. A module used in a subcomponent was added to a parent component accidentally and triggered this error. Unfortunately, I cannot share the source code.
Dagger should be able to handle this case, no? |
@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 |
We have a very large codebase and I was made aware of this issue for the first time. I'm not aware it happened before and I can't reproduce it outside of our codebase either. I understand that you can't make random suggestions in the error messages either. May I suggest that you change this error message and ask for help what triggered it? Maybe then you'd get more hints in this ticket. |
This is actually rather easy to reproduce. |
@tasomaniac I know you gave quite a bit of information above, but if you can you provide an example project reproducing the error that would be great? |
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. |
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 |
At least working on this area to make error messages easier to understand with relevant references can make a huge difference even though it means the issue is hard to pinpoint and fix. |
@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 #1793 (comment) 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 #3090 (comment) 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. |
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
The text was updated successfully, but these errors were encountered: