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

Support Kotlin's function mangling #2663

Closed
d1snin opened this issue Jul 21, 2022 · 2 comments
Closed

Support Kotlin's function mangling #2663

d1snin opened this issue Jul 21, 2022 · 2 comments
Labels
status: duplicate A duplicate of another issue

Comments

@d1snin
Copy link

d1snin commented Jul 21, 2022

From the Kotlin documentation:

To mitigate such issues, functions using inline classes are mangled by adding some stable hashcode to the function name. Therefore, fun compute(x: UInt) will be represented as public final void compute-(int x), which solves the clash problem.

Look at the following code:

@JvmInline
value class SomeEntityId(val value: String)

@Repository
interface SomeEntityRepository : JpaRepository<SomeEntity, SomeEntityId> {

    fun findSomeEntityById(id: SomeEntityId): Optional<SomeEntity>
}

Spring Data fails to parse findSomeEntityById function with the following error:

Failed to create query for method public abstract java.util.Optional dev.d1s.test.repository.SomeEntityRepository.findSomeEntityById-956swU4(java.lang.String)! Unable to locate Attribute  with the the given name [id-956swU4]

Currently, I can solve such a problem by adding the @JvmName annotation:

@Repository
interface SomeEntityRepository : JpaRepository<SomeEntity, SomeEntityId> {

    @JvmName("findSomeEntityById")
    @Suppress("INAPPLICABLE_JVM_NAME")
    fun findSomeEntityById(id: SomeEntityId): Optional<SomeEntity>
}

But I find this quite problematic to include these two annotations every single time on every single repository method consuming Kotlin's inline class.

IMO, there is a way to tolerate function mangling. You can simply detect it and cut off the hashcode part from the method name.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 21, 2022
@mp911de
Copy link
Member

mp911de commented Jul 25, 2022

Kotlin's inline-class mechanism randomizes any method names that touch the surface of inline classes. We have the ticket #1947 to address inline classes support so closing this one as duplicate. We also see that Kotlin's approach is less than ideal as it invalidates all assumptions made by frameworks that rely on property names and property paths.

@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Jul 25, 2022
@mp911de mp911de added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 25, 2022
@d1snin
Copy link
Author

d1snin commented Jul 25, 2022

Ok, TY! I'll track the progress on the issue you linked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants