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.

java.util.NoSuchElementException with Dagger 2.27

See original GitHub 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

> 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)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:18 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
bcorsocommented, Jan 13, 2022

@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.

1reaction
0leggcommented, Jan 12, 2022

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 implementation rather than api, 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 --stacktrace there are 0 references to our code, only annotation processor, dagger and java internals.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android build fails when using dagger 2.18 with kotlin kapt
I have added all the required dependencies but upon building my project I am getting the below error. [kapt] An exception occurred: java.util....
Read more >
Introduction to Dagger 2: For Beginners | Medium
This error occurs because dagger does not know which string is firstName and which is lastName so here comes the @Named annotation for...
Read more >
NoSuchElementException - Android Developers
Constructs a NoSuchElementException , saving a reference to the error message string s for later retrieval by the getMessage method.
Read more >
NoSuchElementException (Java Platform SE 8 )
Class NoSuchElementException · Constructor Summary · Method Summary · Methods inherited from class java.lang.Throwable · Methods inherited from class java.lang.
Read more >
Dagger
Dagger is a fully static, compile-time dependency injection framework for both Java and Android. It is developed by the Java Core Libraries Team...
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