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

[KSP] java.lang.IllegalStateException: Unexpected element #4046

Closed
skydoves opened this issue Aug 31, 2023 · 15 comments
Closed

[KSP] java.lang.IllegalStateException: Unexpected element #4046

skydoves opened this issue Aug 31, 2023 · 15 comments

Comments

@skydoves
Copy link

skydoves commented Aug 31, 2023

I've encountered the following issues, and what's intriguing is that my project doesn't involve the use of any Room compiler or similar components.

[ksp] java.lang.IllegalStateException: Unexpected element: dagger.spi.shaded.androidx.room.compiler.processing.ksp.synthetic.KspSyntheticPropertyMethodElement$Setter$SyntheticExecutableParameterElement@f29df7f
	at dagger.spi.shaded.androidx.room.compiler.processing.compat.XConverters.getProcessingEnv(XConverters.kt:285)
	at dagger.internal.codegen.xprocessing.XElements.isFromJavaSource(XElements.java:389)
	at dagger.internal.codegen.binding.Nullability.isKotlinTypeNullable(Nullability.java:65)
	at dagger.internal.codegen.binding.Nullability.of(Nullability.java:52)
	at dagger.internal.codegen.binding.DependencyRequestFactory.newDependencyRequest(DependencyRequestFactory.java:228)
	at dagger.internal.codegen.binding.DependencyRequestFactory.forRequiredResolvedVariable(DependencyRequestFactory.java:139)
	at dagger.internal.codegen.binding.DependencyRequestFactory.forRequiredResolvedVariables(DependencyRequestFactory.java:76)
	at dagger.internal.codegen.binding.InjectionSiteFactory$InjectionSiteVisitor.visitMethod(InjectionSiteFactory.java:122)
	at dagger.internal.codegen.binding.InjectionSiteFactory$InjectionSiteVisitor.visit(InjectionSiteFactory.java:96)
	at dagger.internal.codegen.binding.InjectionSiteFactory.getInjectionSites(InjectionSiteFactory.java:73)
	at dagger.internal.codegen.binding.BindingFactory.membersInjectionBinding(BindingFactory.java:518)
	at dagger.internal.codegen.validation.InjectBindingRegistryImpl.tryRegisterMembersInjectedType(InjectBindingRegistryImpl.java:318)
	at dagger.internal.codegen.validation.InjectBindingRegistryImpl.tryRegisterInjectMethod(InjectBindingRegistryImpl.java:297)
	at dagger.internal.codegen.processingstep.InjectProcessingStep.process(InjectProcessingStep.java:77)
	at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.lambda$process$0(TypeCheckingProcessingStep.java:82)
	at com.google.common.collect.SingletonImmutableBiMap.forEach(SingletonImmutableBiMap.java:68)
	at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.process(TypeCheckingProcessingStep.java:70)
	at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.process(TypeCheckingProcessingStep.java:48)
	at dagger.spi.shaded.androidx.room.compiler.processing.XProcessingStep.process(XProcessingStep.kt:59)
	at dagger.spi.shaded.androidx.room.compiler.processing.CommonProcessorDelegate.processRound(XBasicAnnotationProcessor.kt:130)
	at dagger.spi.shaded.androidx.room.compiler.processing.ksp.KspBasicAnnotationProcessor.process(KspBasicAnnotationProcessor.kt:62)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$8$1.invoke(KotlinSymbolProcessingExtension.kt:305)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$8$1.invoke(KotlinSymbolProcessingExtension.kt:303)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.handleException(KotlinSymbolProcessingExtension.kt:409)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.doAnalysis(KotlinSymbolProcessingExtension.kt:303)
	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:112)
	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:88)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:256)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:42)
	at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:115)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:247)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:87)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:47)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:168)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:53)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:100)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:46)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1497)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
	at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
	at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Unknown Source)
	at java.rmi/sun.rmi.transport.Transport.serviceCall(Unknown Source)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Unknown Source)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)
@kuanyingchou
Copy link
Collaborator

Thanks for reporting. This looks like a bug in Room's XProcessing, a library Dagger uses for KSP migration. I'll include a fix in the next version.

copybara-service bot pushed a commit to androidx/androidx that referenced this issue Sep 1, 2023
Test: n/a

Bug: google/dagger#4046
Change-Id: I8d185c76bc618876bb2f4a30ffc6806f3b9f16bf
@donchummar
Copy link

I guess this has not been released yet if yes when is next release planned ?

@paladin952
Copy link

I have the same issue

@bcorso
Copy link

bcorso commented Sep 22, 2023

I guess this has not been released yet if yes when is next release planned ?

We're still hoping to get fixes for a few more issues in before doing another release (particularly, the incremental processing issues in #4063, #4060, #4054). Also, FYI, if you're really itching to get this fix you can always check out the HEAD-SNAPSHOT artifacts until the next official release is out.

@paladin952
Copy link

paladin952 commented Sep 23, 2023

Thanks for reporting. This looks like a bug in Room's XProcessing, a library Dagger uses for KSP migration. I'll include a fix in the next version.

Hi @kuanyingchou

I tried updating to HEAD-SNAPSHOT but I still face the same issues.
Am I doing something wrong? my understading was that the latest snapshot has this fix.

kotlin = "1.9.10"
ksp = "1.9.10-1.0.13"
agp = "8.1.1"
kotlinCompilerExtension = "1.5.3"

Thank you!

Screenshot 2023-09-23 at 10 28 36 PM

@bcorso
Copy link

bcorso commented Sep 23, 2023

Thanks for trying it out and reporting back. Looks like the issues is that we haven't drop the new XProcessing jars into Dagger. That should be done once #4077 is submitted (probably on Monday).

@donchummar
Copy link

donchummar commented Sep 24, 2023

Hi i have fixed the issue by finding the root cause , we had 3 project but 2 of them does not have nay issue implementing latest 2.48 and it was one specific code that cause this error in one project

It was an annotation in our code

"@set:Inject "

when i removed it was no more referencing to room compiler error , i am not sure why it was happening but removing that solved my issue

@paladin952 your code also might have something like this, i found out this by removing module by module and narrowed down to file and specific set of code

Thank you @bcorso for the prompt

@paladin952
Copy link

paladin952 commented Sep 24, 2023

Hi i have fixed the issue by finding the root cause , we had 3 project but 2 of them does not have nay issue implementing latest 2.48 and it was one specific code that cause this error in one project

It was an annotation in our code

"@set:Inject "

when i removed it was no more referencing to room compiler error , i am not sure why it was happening but removing that solved my issue

@paladin952 your code also might have something like this, i found out this by removing module by module and narrowed down to file and specific set of code

Thank you @bcorso for the prompt

❤️ thanks a lot! you are right. I had one instance of @set:inject ...
Removing that fixes the issues.

Thank you a lot!

@bcorso
Copy link

bcorso commented Sep 26, 2023

Okay, the updated XProcessing jars have been dropped into Dagger so I'm going to close this.

The changes should be available in the HEAD-SNAPSHOT artifacts, and will be included in the next official Dagger release.

@bcorso bcorso closed this as completed Sep 26, 2023
@VincentMasselis
Copy link

I'm posting my issue here since it seems to be related to this thread, I just updated to Dagger 2.48.1 which should fix this issue, now I'm facing this crash when compiling:

[ksp] java.lang.IllegalStateException: Don't know how to convert element of type 'class dagger.spi.shaded.androidx.room.compiler.processing.ksp.synthetic.KspSyntheticPropertyMethodElement$Setter$SyntheticExecutableParameterElement' to KSP
	at dagger.spi.shaded.androidx.room.compiler.processing.compat.XConverters.toKS(XConverters.kt:205)
	at dagger.internal.codegen.xprocessing.XElements.isFromJavaSource(XElements.java:393)
	at dagger.internal.codegen.binding.Nullability.isKotlinTypeNullable(Nullability.java:65)
	at dagger.internal.codegen.binding.Nullability.of(Nullability.java:52)
	at dagger.internal.codegen.binding.DependencyRequestFactory.newDependencyRequest(DependencyRequestFactory.java:228)
	at dagger.internal.codegen.binding.DependencyRequestFactory.forRequiredResolvedVariable(DependencyRequestFactory.java:139)
	at dagger.internal.codegen.binding.DependencyRequestFactory.forRequiredResolvedVariables(DependencyRequestFactory.java:76)
	at dagger.internal.codegen.binding.InjectionSiteFactory$InjectionSiteVisitor.visitMethod(InjectionSiteFactory.java:122)
	at dagger.internal.codegen.binding.InjectionSiteFactory$InjectionSiteVisitor.visit(InjectionSiteFactory.java:96)
	at dagger.internal.codegen.binding.InjectionSiteFactory.getInjectionSites(InjectionSiteFactory.java:73)
	at dagger.internal.codegen.binding.BindingFactory.membersInjectionBinding(BindingFactory.java:518)
	at dagger.internal.codegen.validation.InjectBindingRegistryImpl.tryRegisterMembersInjectedType(InjectBindingRegistryImpl.java:366)
	at dagger.internal.codegen.validation.InjectBindingRegistryImpl.tryRegisterInjectMethod(InjectBindingRegistryImpl.java:339)
	at dagger.internal.codegen.processingstep.InjectProcessingStep.process(InjectProcessingStep.java:77)
	at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.lambda$process$0(TypeCheckingProcessingStep.java:82)
	at com.google.common.collect.RegularImmutableMap.forEach(RegularImmutableMap.java:196)
	at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.process(TypeCheckingProcessingStep.java:70)
	at dagger.internal.codegen.processingstep.TypeCheckingProcessingStep.process(TypeCheckingProcessingStep.java:48)
	at dagger.spi.shaded.androidx.room.compiler.processing.XProcessingStep.process(XProcessingStep.kt:59)
	at dagger.spi.shaded.androidx.room.compiler.processing.CommonProcessorDelegate.processRound(XBasicAnnotationProcessor.kt:130)
	at dagger.spi.shaded.androidx.room.compiler.processing.ksp.KspBasicAnnotationProcessor.process(KspBasicAnnotationProcessor.kt:62)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$8$1.invoke(KotlinSymbolProcessingExtension.kt:305)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$8$1.invoke(KotlinSymbolProcessingExtension.kt:303)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.handleException(KotlinSymbolProcessingExtension.kt:409)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.doAnalysis(KotlinSymbolProcessingExtension.kt:303)
	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:112)
	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:88)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:256)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:42)
	at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:115)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:247)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:87)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:47)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:168)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:53)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:100)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:46)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1497)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
	at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
	at java.rmi/sun.rmi.transport.Transport$1.run(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Unknown Source)
	at java.rmi/sun.rmi.transport.Transport.serviceCall(Unknown Source)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(Unknown Source)
	at java.base/java.security.AccessController.doPrivileged(Unknown Source)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)

As you can see, the stacktrace is a little bit different but looks the same.

You can read the complete failed build here: https://github.com/VincentMasselis/TPMS-advanced/actions/runs/6419647393/job/17429926373

@kuanyingchou
Copy link
Collaborator

Hi, @VincentMasselis , thanks for reporting. Looks like we still missed some types here. I'll try to replace
XElements.isFromJavaSource and XElements.isFromKotlinSource with something more robust.

@VincentMasselis
Copy link

@kuanyingchou Tell me when it's done, I can try snapshot releases my repo easily

@kuanyingchou
Copy link
Collaborator

Hi, @VincentMasselis , the fix is in now. Could you give HEAD-SNAPSHOT a try?

@VincentMasselis
Copy link

I'm no longer facing this compilation crash ! Thanks @kuanyingchou !

But I'm facing a new one :/ I'll create a new github issue to report it

@rakshitsoni02
Copy link

@VincentMasselis had the same issue but looks like fixed as HEAD-SNAPSHOT is not giving the compilation error, hope we will get stable release soon

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

7 participants