Comments (14)
Are there any compilation errors higher up? I think this might happen if you are trying to inject a type that does not exist (i.e., a missing class), but I'm also not exactly sure.
The code problem is here where the dependency request's type is attempted to be converted to an element. This ends up returning null
, presumably as documented: "Returns null
if the type is not one with a corresponding element." MoreElements
then attempts to invoke a method on that null
element which causes the NPE.
from dagger.
Debugging the annotation processor, it seems that I have this missing from my component:
@Named(FrameworkModule.ADMOB_TEST_DEVICES)
String[] admobTestDevices();
Adding that made the build progress and now I'm getting this:
Caused by: java.lang.IllegalArgumentException: java.lang.String[] does not represent a declared type
at com.google.auto.common.MoreTypes$CastingTypeVisitor.defaultAction(MoreTypes.java:581)
at com.google.auto.common.MoreTypes$CastingTypeVisitor.defaultAction(MoreTypes.java:579)
at com.sun.tools.javac.code.Type$ArrayType.accept(Type.java:1117)
at com.google.auto.common.MoreTypes.asDeclared(MoreTypes.java:424)
at dagger.internal.codegen.MethodSignatureFormatter.nameOfType(MethodSignatureFormatter.java:89)
at dagger.internal.codegen.MethodSignatureFormatter.format(MethodSignatureFormatter.java:60)
at dagger.internal.codegen.BindingGraphValidator.validateComponentScope(BindingGraphValidator.java:118)
at dagger.internal.codegen.BindingGraphValidator.validate(BindingGraphValidator.java:54)
at dagger.internal.codegen.ComponentProcessingStep.process(ComponentProcessingStep.java:71)
at dagger.internal.codegen.ComponentProcessor.process(ComponentProcessor.java:146)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
at com.sun.tools.javac.main.Main.compile(Main.java:523)
from dagger.
It looks like the code generation for the component doesn't know how to call the method when it returns an array. I suppose MethodSignatureFormatter.nameOfType
should try to call MoreTypes.asArray
as there are types that are not primitives nor declared.
from dagger.
Cool. Keep 'em coming. Proper error messages will be a big focus before a
release can happen.
On Nov 18, 2014 12:59 AM, "Serandel" [email protected] wrote:
It looks like the code generation for the component doesn't know how to
call the method when it returns an array. I suppose
MethodSignatureFormatter.nameOfType should try to call MoreTypes.asArray
as there are types that are not primitives nor declared.—
Reply to this email directly or view it on GitHub
#75 (comment).
from dagger.
Yeah - that's definitely a bug in how we generate. :(
On Tue Nov 18 2014 at 10:11:02 AM Jake Wharton [email protected]
wrote:
Cool. Keep 'em coming. Proper error messages will be a big focus before a
release can happen.
On Nov 18, 2014 12:59 AM, "Serandel" [email protected] wrote:It looks like the code generation for the component doesn't know how to
call the method when it returns an array. I suppose
MethodSignatureFormatter.nameOfType should try to call MoreTypes.asArray
as there are types that are not primitives nor declared.—
Reply to this email directly or view it on GitHub
#75 (comment).—
Reply to this email directly or view it on GitHub
#75 (comment).
from dagger.
Ok - can this be reproduced on the current snapshots? We've done a lot of re-writing in this code-path, so I'm going to close this for now, but if you can reproduce this with current snapshots, please re-open, ideally with a repro case.
from dagger.
I'm trying to migrate my project from dagger to dagger-2.0 ('com.google.dagger:dagger-compiler:2.0' from jcenter), but build failed.
Caused by: java.lang.IllegalArgumentException: com.github.baoti.git.GitSource[] does not represent a d eclared type at dagger.shaded.auto.common.MoreTypes$CastingTypeVisitor.defaultAction(MoreTypes.java:770) at dagger.shaded.auto.common.MoreTypes$CastingTypeVisitor.defaultAction(MoreTypes.java:768) at com.sun.tools.javac.code.Type$ArrayType.accept(Type.java:1117) at dagger.shaded.auto.common.MoreTypes.asDeclared(MoreTypes.java:524) at dagger.internal.codegen.MethodSignatureFormatter.nameOfType(MethodSignatureFormatter.java:1 09) at dagger.internal.codegen.MethodSignatureFormatter.format(MethodSignatureFormatter.java:77) at dagger.internal.codegen.MethodSignatureFormatter.format(MethodSignatureFormatter.java:49) at dagger.internal.codegen.BindingGraphValidator.validateComponentScope(BindingGraphValidator. java:541) at dagger.internal.codegen.BindingGraphValidator.validate(BindingGraphValidator.java:118) at dagger.internal.codegen.BindingGraphValidator.validate(BindingGraphValidator.java:111) at dagger.internal.codegen.ComponentProcessingStep.process(ComponentProcessingStep.java:77) at dagger.shaded.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:22 8) at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvi ronment.java:794) at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessi ngEnvironment.java:705) at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnviro nment.java:91) at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironm ent.java:1035) at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvir onment.java:1176) at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170) at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856) at com.sun.tools.javac.main.Main.compile(Main.java:523) ... 66 more
from dagger.
@baoti Looking at the referenced code from the stacktrace (BindingGraphValidator.java:541 and MethodSignatureFormatter.java:77) it seems like you have a method in either your component or module that returns an array of GitSource
and incorrectly has dependencies of different scopes (or some other issue related to scopes, see the comment in BindingGraphValidator).
Indeed your error is shadowed by one thrown when trying to build the error message, because of the array type, which is the same error as in the 3rd comment above
@cgruber This does not seem to have been fixed:
Since 2.0 there's a new special case for
void
but it'll still fail for arrays I believe.from dagger.
@tbroyer Thanks for your nice explaining!
from dagger.
But I doesn't understand why is dagger.shaded.auto.common.MoreTypes
in my stacktrace, but com.google.auto.common.MoreTypes
in serandel's stacktrace.
I didn't found the dagger.shaded.auto.common.MoreTypes
class in this repository.
from dagger.
@baoti It's com.google.auto.common.MoreTypes
that's been renamed (shaded, by the maven-shade-plugin) at build-time to avoid runtime conflicts.
from dagger.
👍
from dagger.
I'll bump this up. We're hoping for a 2.0.1 nearly immediately, but this seems worth fixing and getting in to that.
from dagger.
I just had this error message with Dagger 2.0.1:
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> java.lang.IllegalArgumentException: com.example.Project[] does not represent a declared type
The problem was that I didn't write a Project[] getProjects();
in the component that my component depends on.
If the Type is Project
instead of Project[]
the error is correct:
Error:(31, 10) error: com.example.Project cannot be provided without an @Inject constructor or from an @Provides- or @Produces-annotated method.
com.example.MainActivity.projects
[injected field of type: com.example.Project projects]
from dagger.
Related Issues (20)
- Multibinding with Nested Complex Keys uses the wrong AnnotationCreator HOT 1
- [Hilt] onCreate() in my Application doesn't called on Instrument test HOT 4
- [Dagger-Hilt] Error when applying obfuscation other than Proguard (Allatori) HOT 3
- error: [Hilt] Expected @AndroidEntryPoint to have a value HOT 3
- @IntoSet analog for injectable classes HOT 3
- Hilt Generated Code having not used code? HOT 2
- [Dagger-Hilt] Can't get viewModel in composable by Hilt HOT 6
- Why does Provides in a Companion Object work? HOT 6
- Update Dagger guava dependency to address CVE-2023-2976 HOT 2
- Add KMP support for @HiltViewModel annotation HOT 2
- Dagger resolution and dynamic feature module HOT 1
- Feature request: Manually regenerate application component HOT 1
- Using TestContainer.com HOT 2
- Detect dependency cycles containing Lazy or Provider during the compilation time HOT 6
- error when ksp.useKSP2=true HOT 2
- Suppress annotation on @Inject is not honored on the Factory HOT 1
- [KSP2] Dagger and Hilt incompatibility with KSP2 HOT 4
- [KSP2] NullPointerException: null cannot be cast to non-null type androidx.room.compiler.processing.XType HOT 1
- App crashing with NPE for some classes when Lazy Class Key is used HOT 7
- OutOfMemoryError with Maven HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dagger.