Skip to content
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

NPE while building, no error message to show why #75

Closed
serandel opened this issue Nov 18, 2014 · 14 comments
Closed

NPE while building, no error message to show why #75

serandel opened this issue Nov 18, 2014 · 14 comments
Assignees
Milestone

Comments

@serandel
Copy link

I'm experimenting with the latest snapshot of Dagger 2 and I'm getting this error while building:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:compileDebugJava'.
    at     org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)

[snip]

Caused by: java.lang.NullPointerException
    at com.google.auto.common.MoreElements.asType(MoreElements.java:99)
    at dagger.internal.codegen.BindingGraphValidator.reportMissingBinding(BindingGraphValidator.java:156)
    at dagger.internal.codegen.BindingGraphValidator.access$000(BindingGraphValidator.java:39)
    at dagger.internal.codegen.BindingGraphValidator$1.visitResolvedBinding(BindingGraphValidator.java:70)
    at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:299)
    at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:303)
    at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:303)
    at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:303)
    at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:303)
    at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:303)
    at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:303)
    at dagger.internal.codegen.BindingGraphValidator.validate(BindingGraphValidator.java:61)
    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)
    ... 66 more

I'm sure I have a missing binding, but surely would appreciate Dagger telling me which one. :)

@JakeWharton
Copy link

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.

@serandel
Copy link
Author

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)

@serandel
Copy link
Author

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.

@JakeWharton
Copy link

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" notifications@github.com 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).

@cgruber
Copy link

cgruber commented Nov 19, 2014

Yeah - that's definitely a bug in how we generate. :(

On Tue Nov 18 2014 at 10:11:02 AM Jake Wharton notifications@github.com
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" notifications@github.com 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).

@cgruber
Copy link

cgruber commented Mar 26, 2015

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.

@cgruber cgruber closed this as completed Mar 26, 2015
@baoti
Copy link

baoti commented May 17, 2015

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

@tbroyer
Copy link

tbroyer commented May 17, 2015

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

@baoti
Copy link

baoti commented May 18, 2015

@tbroyer Thanks for your nice explaining!

@baoti
Copy link

baoti commented May 18, 2015

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.

@tbroyer
Copy link

tbroyer commented May 18, 2015

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

@baoti
Copy link

baoti commented May 18, 2015

👍

@cgruber
Copy link

cgruber commented May 18, 2015

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.

@BraisGabin
Copy link

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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants