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 Common Metadata Task Fails with null for default annotation arguments #885

Open
agrosner opened this issue Mar 4, 2022 · 11 comments
Open
Assignees
Labels
AA waiting for upstream fix
Milestone

Comments

@agrosner
Copy link

agrosner commented Mar 4, 2022

KSP Version: 1.6.10-1.0.4

I have a class defined in commonMain for a testing module:

@Table
data class SimpleModel(@PrimaryKey val id: String)

The place it fails is here

where I am taking the KSValueArgument and inferring return type into a data model in order to grab its value. When I run the processor on a specific target like jvm or android, it finds the proper default values. But running the common metadata task:

 Task :tests:kspKotlinMetadata FAILED
e: [ksp] java.lang.NullPointerException: null cannot be cast to non-null type kotlin.Boolean
	at com.dbflow5.ksp.parser.KSPropertyDeclarationParser.parse(KSPropertyDeclarationParser.kt:135)

All arguments are null from the corresponding annotation

like:

annotation class PrimaryKey(
    /**
     * Specifies if the column is autoincrementing or not
     */
    val autoincrement: Boolean = false, // this should not be null if missing...

The fix is to ignore default values when null and also supply defaults in the processor, but that would introduce unnecessary duplication to keep the arguments up with their default values...

@neetopia
Copy link
Contributor

This is still pending upstream fix, likely won't make it in 1.7.0 release.

@lukellmann
Copy link
Contributor

Any updates on this?

@neetopia
Copy link
Contributor

neetopia commented Apr 4, 2023

No, it is not prioritized at the moment

@lukellmann
Copy link
Contributor

Can I somehow help with this? Is it a problem with KSP or the Kotlin compiler?

@neetopia
Copy link
Contributor

The problem is within kotlin compiler, the compiler does not propagate the default arguments value into the metadata artifacts, therefore when such artifacts are used as a dependency, there is no way to get the value from it. It works in JVM because we manually parsed class files to get the value, but class files are not available on other platforms.

@lukellmann
Copy link
Contributor

Is there already an issue in the Kotlin YouTrack?

@neetopia
Copy link
Contributor

Not sure, I will file one if it is not yet created.

@lukellmann
Copy link
Contributor

Not sure, I will file one if it is not yet created.

Could you provide the issue link so I can follow along there? I wasn't able to find it.

@neetopia
Copy link
Contributor

Thanks for the reminder, created one in YouTrack: https://youtrack.jetbrains.com/issue/KT-59566/Annotation-default-value-is-not-populated-in-metadata-for-libraries

@eygraber
Copy link

eygraber commented Feb 8, 2024

I started seeing something similar after updating to KSP2:

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:419)
        at com.google.devtools.ksp.impl.symbol.kotlin.KSAnnotationImpl$defaultArguments$2.invoke(KSAnnotationImpl.kt:77)
        at com.google.devtools.ksp.impl.symbol.kotlin.KSAnnotationImpl$defaultArguments$2.invoke(KSAnnotationImpl.kt:60)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at com.google.devtools.ksp.impl.symbol.kotlin.KSAnnotationImpl.getDefaultArguments(KSAnnotationImpl.kt:60)
        at com.google.devtools.ksp.impl.symbol.kotlin.KSAnnotationImpl$arguments$2.invoke(KSAnnotationImpl.kt:54)
        at com.google.devtools.ksp.impl.symbol.kotlin.KSAnnotationImpl$arguments$2.invoke(KSAnnotationImpl.kt:51)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at com.google.devtools.ksp.impl.symbol.kotlin.KSAnnotationImpl.getArguments(KSAnnotationImpl.kt:51)
        at com.google.devtools.ksp.impl.symbol.kotlin.KSPropertyDeclarationImpl$annotations$2$4.invoke(KSPropertyDeclarationImpl.kt:65)
        at com.google.devtools.ksp.impl.symbol.kotlin.KSPropertyDeclarationImpl$annotations$2$4.invoke(KSPropertyDeclarationImpl.kt:61)
        at kotlin.sequences.FilteringSequence$iterator$1.calcNext(Sequences.kt:171)
        at kotlin.sequences.FilteringSequence$iterator$1.hasNext(Sequences.kt:194)
        at kotlin.sequences.FlatteningSequence$iterator$1.ensureItemIterator(Sequences.kt:331)
        at kotlin.sequences.FlatteningSequence$iterator$1.hasNext(Sequences.kt:318)
        at com.google.devtools.ksp.visitor.KSValidateVisitor.visitAnnotated(KSValidateVisitor.kt:126)
        at com.google.devtools.ksp.visitor.KSValidateVisitor.visitDeclaration(KSValidateVisitor.kt:23)

Is this the same issue, and would https://youtrack.jetbrains.com/issue/KT-59526/Store-annotation-default-values-in-metadata-on-JVM fix it?

@BoD
Copy link

BoD commented Sep 19, 2024

@eygraber It doesn't seem clear if this is the same issue so I just opened #2112

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AA waiting for upstream fix
Projects
None yet
Development

No branches or pull requests

6 participants