You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In kotlin, non-nullable Int is compiled to java primitive type int, this cause the condition candidateParameter.equals(genericParameter.toClass() always evaluates to false. so org.springframework.core.BridgeMethodResolver#findBridgedMethod fails to find the correct bridge method.
Due to this issue, the @Transactional on delete(id: Int) method have no effects at all.
I'm not sure if this project is expected to be compatible with Kotlin code. If it is, then this is a bug, I think I can try to submit a PR to fix it.
The text was updated successfully, but these errors were encountered:
@jhoeller I have little experience with bridge methods, but based on my initial findings with this test, my current thinking is that we could add Kotlin specific code path in BridgeMethodResolver#isResolvedTypeMatch.
Instead of just doing Type[] genericParameters = genericMethod.getGenericParameterTypes(), we should maybe use KClass<T>.javaObjectType in order to get a type that will be compatible with the rest f the logic. In the use case we have here, java.lang.Integer would be returned for both Kotlin Int and Int? types. But I am not sure KClass<T>.javaObjectType is exposed in Java, to be checked with Kotlin team.
I think you mentioned another potential way to fix that, but I can't remember the details. Any thoughts?
@noob9527 Since you mentioned a PR, any thoughts on what could look like the fix?
@sdeleuze
I think ResolvableType.forMethodParameter(genericMethod, i, declaringClass); will always return a wrapper type.
so we can just wrap candidateParameter to its wrapper type before comparing.
This commit adds support for Kotlin non-nullable type which resolves
to primitive Java types in BridgeMethodResolver#findBridgedMethod.
Closesspring-projectsgh-26585
lxbzmy
pushed a commit
to lxbzmy/spring-framework
that referenced
this issue
Mar 26, 2022
This commit adds support for Kotlin non-nullable type which resolves
to primitive Java types in BridgeMethodResolver#findBridgedMethod.
Closesspring-projectsgh-26585
Affects: v5.3.4
In kotlin, non-nullable Int is compiled to java primitive type int, this cause the condition
candidateParameter.equals(genericParameter.toClass()
always evaluates tofalse
. soorg.springframework.core.BridgeMethodResolver#findBridgedMethod
fails to find the correct bridge method.the above "GenericRepository" is compiled to
Due to this issue, the
@Transactional
ondelete(id: Int)
method have no effects at all.I'm not sure if this project is expected to be compatible with Kotlin code. If it is, then this is a bug, I think I can try to submit a PR to fix it.
The text was updated successfully, but these errors were encountered: