Git Product home page Git Product logo

Comments (14)

JakeWharton avatar JakeWharton commented on April 28, 2024

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.

serandel avatar serandel commented on April 28, 2024

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.

serandel avatar serandel commented on April 28, 2024

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.

JakeWharton avatar JakeWharton commented on April 28, 2024

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.

cgruber avatar cgruber commented on April 28, 2024

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.

cgruber avatar cgruber commented on April 28, 2024

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.

baoti avatar baoti commented on April 28, 2024

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.

tbroyer avatar tbroyer commented on April 28, 2024

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

private static String nameOfType(TypeMirror type) {
if (type.getKind().isPrimitive()) {
return MoreTypes.asPrimitiveType(type).toString();
} else if (type.getKind() == TypeKind.VOID) {
return "void";
} else {
return stripCommonTypePrefixes(MoreTypes.asDeclared(type).toString());
}
}

Since 2.0 there's a new special case for void but it'll still fail for arrays I believe.

from dagger.

baoti avatar baoti commented on April 28, 2024

@tbroyer Thanks for your nice explaining!

from dagger.

baoti avatar baoti commented on April 28, 2024

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.

tbroyer avatar tbroyer commented on April 28, 2024

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

baoti avatar baoti commented on April 28, 2024

👍

from dagger.

cgruber avatar cgruber commented on April 28, 2024

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.

BraisGabin avatar BraisGabin commented on April 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.