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

Room + KSP : KSErrorType cannot be cast to class KSTypeImpl #796

Closed
kuFEAR opened this issue Jan 14, 2022 · 2 comments
Closed

Room + KSP : KSErrorType cannot be cast to class KSTypeImpl #796

kuFEAR opened this issue Jan 14, 2022 · 2 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@kuFEAR
Copy link

kuFEAR commented Jan 14, 2022

Hi, I've encountered a bug in a multi-module project with Room 2.4.0 and KSP version 1.6.10-1.0.2. Is this a problem on the KSP or Room side?

Stacktrace

e: java.lang.IllegalStateException: failed to analyze: java.lang.ClassCastException: class com.google.devtools.ksp.symbol.impl.kotlin.KSErrorType cannot be cast to class com.google.devtools.ksp.symbol.impl.kotlin.KSTypeImpl (com.google.devtools.ksp.symbol.impl.kotlin.KSErrorType and com.google.devtools.ksp.symbol.impl.kotlin.KSTypeImpl are in unnamed module of loader java.net.URLClassLoader @201b740a)
at org.jetbrains.kotlin.analyzer.AnalysisResult.throwIfError(AnalysisResult.kt:56)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:105)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:58)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:170)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:52)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:92)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:44)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:98)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1618)
at jdk.internal.reflect.GeneratedMethodAccessor193.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.ClassCastException: class com.google.devtools.ksp.symbol.impl.kotlin.KSErrorType cannot be cast to class com.google.devtools.ksp.symbol.impl.kotlin.KSTypeImpl (com.google.devtools.ksp.symbol.impl.kotlin.KSErrorType and com.google.devtools.ksp.symbol.impl.kotlin.KSTypeImpl are in unnamed module of loader java.net.URLClassLoader @201b740a)
at com.google.devtools.ksp.symbol.impl.UtilsKt.toKotlinType(utils.kt:351)
at com.google.devtools.ksp.symbol.impl.UtilsKt.replaceTypeArguments(utils.kt:369)
at com.google.devtools.ksp.symbol.impl.kotlin.KSTypeImpl.replace(KSTypeImpl.kt:94)
at androidx.room.compiler.processing.ksp.KSTypeVarianceResolver.inheritVariance(KSTypeVarianceResolver.kt:87)
at androidx.room.compiler.processing.ksp.KSTypeVarianceResolver.applyTypeVariance(KSTypeVarianceResolver.kt:53)
at androidx.room.compiler.processing.ksp.KspProcessingEnv.resolveWildcards(KspProcessingEnv.kt:275)
at androidx.room.compiler.processing.ksp.KspJvmTypeResolver.resolveJvmType$room_compiler_processing(KspJvmTypeResolver.kt:48)
at androidx.room.compiler.processing.ksp.KspType$typeName$2.invoke(KspType.kt:52)
at androidx.room.compiler.processing.ksp.KspType$typeName$2.invoke(KspType.kt:51)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at androidx.room.compiler.processing.ksp.KspType.getTypeName(KspType.kt:51)
at androidx.room.processor.CustomConverterProcessor.processMethod(CustomConverterProcessor.kt:173)
at androidx.room.processor.CustomConverterProcessor.process(CustomConverterProcessor.kt:135)
at androidx.room.processor.CustomConverterProcessor$Companion.findConverters(CustomConverterProcessor.kt:67)
at androidx.room.processor.Context.fork(Context.kt:155)
at androidx.room.processor.Context.fork$default(Context.kt:153)
at androidx.room.processor.DatabaseProcessor.(DatabaseProcessor.kt:50)
at androidx.room.DatabaseProcessingStep$process$databases$1$1.invoke(DatabaseProcessingStep.kt:71)
at androidx.room.DatabaseProcessingStep$process$databases$1$1.invoke(DatabaseProcessingStep.kt:70)
at androidx.room.processor.Context.collectLogs(Context.kt:149)
at androidx.room.DatabaseProcessingStep.process(DatabaseProcessingStep.kt:70)
at androidx.room.DatabaseProcessingStep.process(DatabaseProcessingStep.kt:41)
at androidx.room.compiler.processing.CommonProcessorDelegate.processRound(XBasicAnnotationProcessor.kt:114)
at androidx.room.compiler.processing.ksp.KspBasicAnnotationProcessor.process(KspBasicAnnotationProcessor.kt:61)
at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$4$1.invoke(KotlinSymbolProcessingExtension.kt:195)
at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$4$1.invoke(KotlinSymbolProcessingExtension.kt:193)
at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.handleException(KotlinSymbolProcessingExtension.kt:287)
at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.doAnalysis(KotlinSymbolProcessingExtension.kt:193)
at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:120)
at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:96)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:262)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:53)
at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:113)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:253)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.repeatAnalysisIfNeeded(KotlinToJVMBytecodeCompiler.kt:223)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:100)
... 23 more

@ting-yuan
Copy link
Collaborator

ting-yuan commented Jan 17, 2022

The exception is thrown because of a miss in error handling in KSP, where KSType.replace() doesn't handle the case where some of the new type arguments are unknown / cannot be resolved.

We'll fix it by adding corresponding error handling logic, so that KSType.replace() will return an error type, instead of throwing an exception like that.

On the other hand, before the fix reaches next KSP release, it might be possible to avoid this error by finding out the unknown type and, if it was not intended, replace it with the desired type.

@ting-yuan ting-yuan added this to the 1.0.3 milestone Jan 17, 2022
@ting-yuan ting-yuan added the bug Something isn't working label Jan 17, 2022
@ting-yuan ting-yuan self-assigned this Feb 2, 2022
@ting-yuan
Copy link
Collaborator

Fixed in #824. Instead of throwing an exception, KSType.replace() will now return an KSErrorType when there's an unresolvable type in the arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants