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

KSP2 crash when using @JsonQualifier #1874

Open
Jean-Daniel opened this issue Jul 31, 2024 · 8 comments
Open

KSP2 crash when using @JsonQualifier #1874

Jean-Daniel opened this issue Jul 31, 2024 · 8 comments
Labels

Comments

@Jean-Daniel
Copy link

Jean-Daniel commented Jul 31, 2024

When trying to generate Adapter for classes using a @JsonQualifier, KSP fails with the error:


> Task :app:kspDebugKotlin FAILED
e: [ksp] Error preparing ApiUserItem: jdk.proxy5/jdk.proxy5.$Proxy154.value(Unknown Source)
com.squareup.moshi.kotlin.codegen.ksp.MoshiApiUtilKt.generator(MoshiApiUtil.kt:77)
com.squareup.moshi.kotlin.codegen.ksp.JsonClassSymbolProcessor.adapterGenerator(JsonClassSymbolProcessorProvider.kt:122)
com.squareup.moshi.kotlin.codegen.ksp.JsonClassSymbolProcessor.process(JsonClassSymbolProcessorProvider.kt:92)
com.google.devtools.ksp.impl.KotlinSymbolProcessing.execute(KotlinSymbolProcessing.kt:538)
com.google.devtools.ksp.impl.KSPLoader$Companion.loadAndRunKSP(KSPLoader.kt:36)
com.google.devtools.ksp.impl.KSPLoader.loadAndRunKSP(KSPLoader.kt)
…

The class being compiled is simply:

@Retention(AnnotationRetention.RUNTIME)
@JsonQualifier
annotation class ISO8061

@JsonClass(generateAdapter = true)
open class ApiUserItem(
  @field:Json(name = "slug") val slug: String,
  @field:Json(name = "date_added") @field:ISO8061 val date: Long,
)

You can use this reduced test case to reproduce the bug.

git clone https://github.com/Jean-Daniel/moshiksp2
cd moshiksp2
./gradlew :app:assembleDebug
> Task :app:kspDebugKotlin FAILED
…
@ZacSweers
Copy link
Collaborator

Upstream KSP2 bug, please file with them

@ting-yuan
Copy link

This is caused by a breaking change in KSP2. @ZacSweers could this copy be deleted and let moshi use the implementation from KSP?

@ting-yuan
Copy link

Removing it doesn't seem to break any tests:
#1875

@Jean-Daniel
Copy link
Author

Can this bug be reopened as this is clearly a Moshi bug as it is the moshi shadedUtil.kt version that is faulty.

@ZacSweers ZacSweers reopened this Dec 17, 2024
@ZacSweers
Copy link
Collaborator

The linked fix isn't a useable fix because it's an unstable API. A more appropriate one would be to update the copied impl to the new one

@malikmudassarhussain
Copy link

malikmudassarhussain commented Dec 20, 2024

While migrating to Koline 2.x I had to fallback to moshi-ksp from moshi-ir because of this IR issue and now I am stuck on the above error. Is there any quick fix as the IR one will be fixed in Kotlin 2.1.20

@Jean-Daniel
Copy link
Author

Is there any quick fix as the IR one will be fixed in Kotlin 2.1.20

Yes, just keep using KSP 1 instead of KSP 2, as only KSP 2 is impacted by this issue.

@Jean-Daniel
Copy link
Author

The linked fix isn't a useable fix because it's an unstable API. A more appropriate one would be to update the copied impl to the new one

I'm not sure I get the 'unstable API' argument.

Using an unstable API can cause mochi to stop working when updating KSP, but this is the same as copying the file, as updating KSP to a version with a different shadedUtil.kt file/API is also breaking Moshi, as shown here.

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

No branches or pull requests

4 participants