google / ksp

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

[KSP2] NPE when getting annotation arguments on non-Jvm targets #1823

Closed DennisTsar closed 2 months ago

DennisTsar commented 7 months ago

Calling KSAnnotation.arguments for an annotation with arguments fails with KSP2 on non-Jvm targets with the following error:

java.lang.NullPointerException: null cannot be cast to non-null type org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl
    at com.google.devtools.ksp.impl.symbol.kotlin.UtilKt.getDefaultValue(util.kt:430)
    at com.google.devtools.ksp.impl.symbol.kotlin.KSAnnotationImpl$defaultArguments$2.invoke(KSAnnotationImpl.kt:88)
    at com.google.devtools.ksp.impl.symbol.kotlin.KSAnnotationImpl$defaultArguments$2.invoke(KSAnnotationImpl.kt:71)
    at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
    at com.google.devtools.ksp.impl.symbol.kotlin.KSAnnotationImpl.getDefaultArguments(KSAnnotationImpl.kt:71)
    at com.google.devtools.ksp.impl.symbol.kotlin.KSAnnotationImpl$arguments$2.invoke(KSAnnotationImpl.kt:65)
    at com.google.devtools.ksp.impl.symbol.kotlin.KSAnnotationImpl$arguments$2.invoke(KSAnnotationImpl.kt:62)
    at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
    at com.google.devtools.ksp.impl.symbol.kotlin.KSAnnotationImpl.getArguments(KSAnnotationImpl.kt:62)

Repro: https://github.com/DennisTsar/ksp/commit/8449e19b446404b31736be325ea65322510d453c This seems similar to #1798 , but does not involve Java in any way.

neetopia commented 6 months ago

This likely requires an upstream fix for metadata for klib.

sureshmaidaragi1919 commented 5 months ago

Any timeline for this bug fix?

neetopia commented 5 months ago

The dependent upstream issue is targeting Kotlin 2.1, we will likely have to wait until then.

jschneider commented 1 month ago

This bug still exists with 2.1.0-Beta1-1.0.25 (Kotlin 2.1.0-Beta1). Any link to the upstream ticket/fix?