google / google/ksp

Java-first annotations disappear when same property comes from multiple superclass sources on KSP2

Open
#2,833 1 comment 3 reactions 0 assignees View on GitHub
bug core P4
Dominant language
Kotlin
Stars
3.5k
Forks
415
Avg merge
1d 2h
Merged PRs (30d)
53

Description

We are currently in the process of migrating our codebase from KSP1 to KSP2 (we are updating to Kotlin 2.2.20 + KSP 2.2.20-2.0.4).

I've noticed a behavioural difference on KSP2 w.r.t. to how `getAllProperties()` handles annotations coming from multiple sources from inherited properties.

I wrote [a simple MRE to showcase the issue](https://github.com/luanpotter/kotlin-testbed/tree/master/get-all-properties); but in essence we have:

```kotlin
interface HasName {
val name: String
}

abstract class BaseEntity {
@Column(name = "name") lateinit var name: String
}

@InspectProperties
class WithInterface : BaseEntity(), HasName
```

Before (with KSP1), the annotations in the properties returned by `getAllProperties()` would include the `@Column` interface as I'd expect. On KSP2, it is no longer included. As far as I can tell, this only happens if:

* `@Column` is defined as a Java interface
* the class inherits from two sources (an abstract class and an interface) that both declare the same column

Feel free to browse the complete MRE [on my repo](https://github.com/luanpotter/kotlin-testbed/tree/master/get-all-properties); there is a `./scripts/run.sh` script to make it easier to see and play around with.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.