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

Kotlin spy beans created with incorrect method signature #505

Open
petergphillips opened this issue Dec 8, 2023 · 0 comments
Open

Kotlin spy beans created with incorrect method signature #505

petergphillips opened this issue Dec 8, 2023 · 0 comments

Comments

@petergphillips
Copy link

Originally raised as Upgrade to Spring Framework 6.1 causes null pointer in CoroutinesUtils, but investigated by Spring there and considered to be a bug here instead.

I've got a reactive kotlin spring boot repository that I'm attempting to spy. The superclass (CoroutineCrudRepository) has methods such as:

	suspend fun findById(id: ID): T?

When autowiring the repository interface using Spring this gets created with a proxy signature of

public final java.lang.Object jdk.proxy3.$Proxy98.findById(java.lang.Object,kotlin.coroutines.Continuation)

Creating a spy from the repository using

mock(defaultAnswer = AdditionalAnswers.delegatesTo(exampleRepository))

then seems to end up with two versions of the findById method:

public java.lang.Object uk.co.greenthistle.coroutinespybeanexample.ExampleRepository$MockitoMock$poIc1iZ2.findById(java.lang.Object,kotlin.coroutines.Continuation)

and also

public java.lang.Object uk.co.greenthistle.coroutinespybeanexample.ExampleRepository$MockitoMock$poIc1iZ2.findById(java.lang.Long,kotlin.coroutines.Continuation)

This seems to then cause the new spring boot code to choose the wrong method and then not be able to find the correct method to call on the spy.

Please see example project demonstrating the issue at https://github.com/petergphillips/spring-coroutine-spybean-example

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

No branches or pull requests

1 participant