mockk: 1.12.5 fails to `every` certain java classes
I created a demo/minimal project here:
https://gitlab.com/knyttl/mockkdemo/-/tree/main
You can see the CI build with test failure here:
https://gitlab.com/knyttl/mockkdemo/-/jobs/2782097977
Feel free to change the build.gradle.kts mockk version to 1.12.4 which will test correctly.
Expected Behavior
The tests shouldn’t fail.
Current Behavior
The test fails with:
kotlin.reflect.jvm.internal.KotlinReflectionInternalError: Unresolved class: class org.elasticsearch.search.sort.SortOrder$1
As you can see in the CI run mentioned above.
Failure Information (for bugs)
See CI run mentioned above.
Steps to Reproduce
See the source code mentioned above. Feel free to change the version to 1.12.4 which will build correctly.
Context
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
- MockK version: 1.12.5
- Kotlin version: 1.7.10
- JDK version: 17
Minimal reproducible code (the gist of this issue)
import io.mockk.every
import io.mockk.mockk
import org.elasticsearch.search.sort.SortOrder
import org.junit.jupiter.api.Test
class MockkDemo {
@Test
fun testMockk() {
val repo = mockk<TestClass>()
every { repo.getSchedules() } returns "Foo"
}
}
class TestClass {
fun getSchedules(sortOrder: SortOrder = SortOrder.ASC): String =
sortOrder.toString()
}
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 10
- Comments: 38 (12 by maintainers)
Commits related to this issue
- value class check - catch KotlinReflectionInternalError might fix #868, caused by #913? — committed to aSemy/mockk by aSemy 2 years ago
When will you release it?
Fixed in 1.13.1
@aSemy however we are already catching KotlinReflectionInternalError. It seems KotlinReflectionInternalError can’t be catched.
I am sorry, but this is not resolved - demo build still fails on 1.12.8:
https://gitlab.com/knyttl/mockkdemo/-/jobs/3032515325
And:
https://github.com/mockk/mockk/pull/890 should fix it
@realjenius oh I wasn’t aware of the fact that is was working in version
1.12.4
. Currently I have no working workaround 😦.I confirm that the problem persists. I updated the demo:
I just tested Mockk 1.12.7 which I believe has #872 and I’m still getting this error in my code as well.
I’ve encountered a very similar issue with 1.12.5, though purely with Kotlin. see https://github.com/ascheja/KotlinReflectionInternalError-reproducer-mockk. In my case there is an issue with a class not being there for a lambda, but the issue only appears in certain scenarios (i.e. with an anonymous class or different surrounding code it works just fine).
I suspect it could be related to https://youtrack.jetbrains.com/issue/KT-41373, but I’m not sure.