java.lang.ClassCastException: class `ksp.org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl` cannot be cast to class `ksp.org.jetbrains.kotlin.fir.declarations.FirResolvedDeclarationStatus`
- Dominant language
- Kotlin
- Stars
- 3.5k
- Forks
- 415
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 53
Description
Hi!
We've just bumped our build setup to `Kotlin 2.2.0` and `KSP 2.2.0-2.0.2`.
We only use a single internal KSP processor that grabs Dagger/Anvil annotations and generates components out of it, it's been working fine before.
Some of our IC builds are failing with the following:
```
> A failure occurred while executing com.google.devtools.ksp.gradle.KspAAWorkerAction
> Error while resolving ksp.org.jetbrains.kotlin.fir.declarations.impl.FirRegularClassImpl
from RAW_FIR to STATUS
current declaration phase STATUS
origin: Source
session: class ksp.org.jetbrains.kotlin.analysis.low.level.api.fir.sessions.LLFirSourcesSession (Kotlin reflection is not available)
module data: class ksp.org.jetbrains.kotlin.analysis.low.level.api.fir.projectStructure.LLFirModuleData (Kotlin reflection is not available)
KaModule: class ksp.org.jetbrains.kotlin.analysis.project.structure.impl.KaSourceModuleImpl (Kotlin reflection is not available)
platform: JVM (21)
```
We don't have repro steps yet and will try running with `--stacktrace` to track it down but is there any other way we could help with investigating the cause of this?
Re-running the same task fixes the issue so it makes it harder to track.
Seems like it's caused by:
**java.lang.ClassCastException: class ksp.org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl cannot be cast to class ksp.org.jetbrains.kotlin.fir.declarations.FirResolvedDeclarationStatus (ksp.org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl and ksp.org.jetbrains.kotlin.fir.declarations.FirResolvedDeclarationStatus are in unnamed module of loader java.net.URLClassLoader @2a6dd688)**
Contributor guide
Research direction
Start by rerunning the failing KspAAWorkerAction task with --stacktrace and capture the intermittent ClassCastException. Investigate the RAW_FIR-to-STATUS resolution path described in the error, then isolate a reproducible project using Kotlin 2.2.0, KSP 2.2.0-2.0.2, and the reported Dagger/Anvil processor. Done means a minimal reproduction or a clearly identified cause and regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100