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

Compilation fails because of an IllegalArgumentException when upgrading to Dagger 2.26 #1735

Closed
quiro91 opened this issue Feb 6, 2020 · 7 comments

Comments

@quiro91
Copy link

quiro91 commented Feb 6, 2020

After upgrading to Dagger 2.26, the build of my app fails with the following stacktrace.

e: [kapt] An exception occurred: java.lang.IllegalArgumentException
        at com.google.common.base.Preconditions.checkArgument(Preconditions.java:128)
        at dagger.internal.codegen.writing.InjectionMethod.invoke(InjectionMethod.java:112)
        at dagger.internal.codegen.writing.InjectionMethods$InjectionSiteMethod.invoke(InjectionMethods.java:358)
        at dagger.internal.codegen.writing.InjectionMethods$InjectionSiteMethod.lambda$invokeAll$0(InjectionMethods.java:326)
        at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
        at java.util.Collections$2.tryAdvance(Collections.java:4719)
        at java.util.Collections$2.forEachRemaining(Collections.java:4727)
        at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
        at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
        at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
        at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566)
        at dagger.internal.codegen.writing.InjectionMethods$InjectionSiteMethod.invokeAll(InjectionMethods.java:334)
        at dagger.internal.codegen.writing.MembersInjectorGenerator.write(MembersInjectorGenerator.java:200)
        at dagger.internal.codegen.writing.MembersInjectorGenerator.write(MembersInjectorGenerator.java:72)
        at dagger.internal.codegen.base.SourceFileGenerator.generate(SourceFileGenerator.java:77)
        at dagger.internal.codegen.validation.InjectBindingRegistryImpl$BindingsCollection.generateBindings(InjectBindingRegistryImpl.java:97)
        at dagger.internal.codegen.validation.InjectBindingRegistryImpl.generateSourcesForRequiredBindings(InjectBindingRegistryImpl.java:191)
        at dagger.internal.codegen.ComponentProcessor.postRound(ComponentProcessor.java:208)
        at dagger.shaded.auto.common.BasicAnnotationProcessor.process(BasicAnnotationProcessor.java:183)
        at org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor.process(incrementalProcessors.kt)
        at org.jetbrains.kotlin.kapt3.base.ProcessorWrapper.process(annotationProcessing.kt:147)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:802)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:713)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1043)
        at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1184)
        at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
        at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1068)
        at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing(annotationProcessing.kt:79)
        at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing$default(annotationProcessing.kt:35)
        at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.runAnnotationProcessing(Kapt3Extension.kt:224)
        at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:187)
        at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:98)
        at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration$2.invoke(TopDownAnalyzerFacadeForJVM.kt:97)
        at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:107)
        at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:82)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:557)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:82)
        at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:107)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:548)
        at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:177)
        at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:165)
        at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:55)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:84)
        at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:42)
        at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:104)
        at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1558)
        at sun.reflect.GeneratedMethodAccessor105.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
        at sun.rmi.transport.Transport$1.run(Transport.java:200)
        at sun.rmi.transport.Transport$1.run(Transport.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
        at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

I can confirm everything was working perfectly on 2.25.4

@trevjonez
Copy link

duplicate or derivative of #1665 ?

@quiro91
Copy link
Author

quiro91 commented Feb 6, 2020

@trevjonez I wouldn't say it's duplicate. While it is true that this error would benefits from better logging, the fact that it worked in 2.25.4 but it doesn't in 2.26 means there's a problem

@trevjonez
Copy link

Either way, I would recommend debugging in to find your root cause so that you can provide a repro example. Otherwise more info in the crash is all they could do

@quiro91
Copy link
Author

quiro91 commented Feb 7, 2020

How can I debug something like this? I tried with --stacktrace and --info but it doesn't give me anything meaningful

@trevjonez
Copy link

First we need to make sure the compiler sources are available in the IDE so we can easily set breakpoints.

if you don't have a buildSrc already:

mkdir buildSrc
touch buildSrc/build.gradle

in that build.gradle add the dagger compiler to the impl configuration.

repositories {
    jcenter()
}

dependencies {
    implementation "com.google.dagger:dagger-compiler:2.26"
}

re-import/sync the project with the IDE.

open InjectionMethod and set a breakpoint on line 112. then right click and set a condition on the breakpoint so it only stops in the failing case.

image

create a debug config in the ide using the Remote template.

image

now we update the gradle jvmargs to instruct the kotlin plugin to run its compilers in-process by adding
-Dkotlin.compiler.execution.strategy="in-process"

//gradle.properties
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m  -Dfile.encoding=UTF-8 -Dkotlin.compiler.execution.strategy="in-process"

next I like to stop all the current gradle daemons just so I know I am in a clean state. (probably not required)
./gradlew --stop

now we can run gradle with a debug flag so that it waits for a debugger to attach, as well as the kapt task or one that depends on it.

./gradlew assembleDebug -Dorg.gradle.debug=true

that will hang until you attach your debugger.

once attached the build will run and you should land on the point of failure with enough information in scope to figure out what code is triggering the failure.

@quiro91
Copy link
Author

quiro91 commented Feb 7, 2020

Looks like in the project there's a class containing a companion object with a member annotated with @set:Inject. Looks like this is not possible anymore after the changes made to companion object in Dagger 2.26. Thanks for the help debugging, I learnt something new today :)

@danysantiago
Copy link
Member

Duplicate of #1665, I'll close this one to keep the discussion on 1665.

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

No branches or pull requests

3 participants