google / ksp

Kotlin Symbol Processing API
https://github.com/google/ksp
Apache License 2.0
2.81k stars 265 forks source link

lateinit property cleanFilenames has not been initialized #952

Open digitalheir opened 2 years ago

digitalheir commented 2 years ago

implementation("com.google.devtools.ksp:symbol-processing-api:1.6.10-1.0.2")

lateinit is kind of like a modern null-pointer exception. I would advise against unless you are 100000% sure this error wil never, ever happen, which is to say I would advise against using it always.

kotlin.UninitializedPropertyAccessException: lateinit property cleanFilenames has not been initialized
    at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.getCleanFilenames(KotlinSymbolProcessingExtension.kt:88)
    at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.doAnalysis(KotlinSymbolProcessingExtension.kt:156)
    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.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:100)
    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.GeneratedMethodAccessor110.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:829)

Error is a racing condition, I think. I can't repro.

neetopia commented 2 years ago

It still confuses me how could there be a race condition, KSP isn't really parallel, will keep this issue open but in a lower priority, until we got a stable reproduce.

digitalheir commented 2 years ago

I am not an expert on the Kotlin compiler like you are but I get the feeling that variable initialization is non-deterministic. In my own apps, I've had similar issues where a circular reference would sometimes and sometimes not cause a null-pointer (because the underlying variable was or wasn't initialized)...

samzurcher commented 2 years ago

FYI: We are seeing this issue every now and then in our project (up-to-date versions). Unfortunately, we don't have a stable reproduction but would be grateful if you guys could look into this issue and find a solution! Thanks a lot!

Zhuinden commented 1 year ago
kotlin.UninitializedPropertyAccessException: lateinit property cleanFilenames has not been initialized
    at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.getCleanFilenames(KotlinSymbolProcessingExtension.kt:116)
    at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.doAnalysis(KotlinSymbolProcessingExtension.kt:220)
    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(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:360)
    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(AccessController.java:712)
    at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)
Errors were stored into D:\Work\...\...\.gradle\kotlin\errors\errors-1691666526668.log

errors-1691666526668.log

Using `classpath 'com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin:1.9.0-1.0.13'

EDIT: but it worked on second execution.

tomkricensky commented 4 months ago

This also happened to me today. Worked on second execution as mentioned above

KSP version 1.9.22-1.0.17

tylerwilson commented 1 month ago

I am seeing the same issue with ksp 2.0.0-1.0.23 in combination with KMP-NativeCoroutines 1.0.0-ALPHA-32.

When I revert to KSP 2.0.0-1.0.21 and KMP NativeCoroutines 1.0.0-ALPHA-31 it builds without issue.

msa1422 commented 1 month ago

+1 to @tylerwilson comment. Facing the same issue in a KMP project for iOS side. And contrary to the comments above, iOS project fails to compile even after multiple execution attempts.

@rickclephas Did you face this issue in any of your projects or testing?

Here is a project that is facing this issue. Updating KSP and KMP NativeCoroutines versions in libs.versions.toml will reproduce this issue. This project is not a Minimum reproducible example, but may help in finding out the root cause.

rickclephas commented 1 month ago

Yeah I have seen this error during testing, but for me it was resolved after performing a clean build.

P.S. I also looked at the relevant KSP code but didn't see any recent changes.

anox1337 commented 1 month ago

I am getting this error on every build since I updated from "2.0.0-1.0.22" to "2.0.0-1.0.23" But ONLY on iOS builds. Android works. Invalidating caches does not help.

> Task :shared:kspKotlinIosSimulatorArm64 FAILED
error: Compilation failed: lateinit property cleanFilenames has not been initialized
msa1422 commented 1 month ago

as @rickclephas mentioned, clean build has worked for me. Thanks Rick.

jamesbluecrow commented 1 month ago

Same here, very weird because I tried cleaning cache and it was still failing when I run ./gradlew ktlintFormat.

But after clean & rebuild it seems to work now.

Thanks @rickclephas 🙏

ArcherEmiya05 commented 3 weeks ago

Is there a fix of this for KMM iOS build? Currently using Kotlin 2.0.10 due to some bug with Room and KSP 2.0.10-1.0.24. Building the iOS part is failing due to this issue and is consistent not intermittent.

GuilhE commented 2 weeks ago

Is there a fix of this for KMM iOS build? Currently using Kotlin 2.0.10 due to some bug with Room and KSP 2.0.10-1.0.24. Building the iOS part is failing due to this issue and is consistent not intermittent.

Same here! Was working with 2.0.20-Beta1-1.0.22 now it fails with 2.0.20-1.0.24

@neetopia here's a reproducible sample, just bump Kotlin and KSP version in libs.versions.toml and run iosApp.

amzada commented 1 week ago

@anox1337 @ArcherEmiya05 have you guys found a fix for this? Facing same issue

GuilhE commented 1 week ago

Is there a fix of this for KMM iOS build? Currently using Kotlin 2.0.10 due to some bug with Room and KSP 2.0.10-1.0.24. Building the iOS part is failing due to this issue and is consistent not intermittent.

Same here! Was working with 2.0.20-Beta1-1.0.22 now it fails with 2.0.20-1.0.24

@neetopia here's a reproducible sample, just bump Kotlin and KSP version in libs.versions.toml and run iosApp.

This is very strange. In the sample I've shared here, I've a module that only contains one class. That class was not being used (just for testing purpose) and it was throwing the error kotlin.UninitializedPropertyAccessException: lateinit property cleanFilenames has not been initialized for this module. So I've commented the unused code and it worked. Then, I uncommented back and it worked again. Cleaned all caches and it worked again. No idea... 🤷🏼

anox1337 commented 1 week ago

@anox1337 @ArcherEmiya05 have you guys found a fix for this? Facing same issue

Not really. I just kept using KSP version 2.0.0-1.0.22 which works for me.

ArcherEmiya05 commented 1 week ago

@anox1337 @ArcherEmiya05 have you guys found a fix for this? Facing same issue

After migrating to Kotlin 2.0.20 and KSP 2.0.20-1.0.24 I no longer encounter this issue. However I am having a separate build issue related to KSP again with Room entities being in a separate module, so I am not sure if that issue is just overtaking this bug. Until that issue got fixed only then I can check if this lateinit bug will show up again.