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
1.12.5 fails to every
certain java classes
#868
Comments
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. |
I guess this is not related as SortOrder (which fails) is not anonymous and also this works with the same Kotlin version, but different mockk version. |
Same error on my ci-system after upgrading to |
I've gotten a similar error when upgrading to The error output in my case:
Unfortunately it's difficult for me to generate an MVE since I am running mockk tests as part of a plugin for the IntelliJ IDE, so the IntelliJ runtime is a dependency during the test. Hopefully someone else has a more lightweight codebase where they could reproduce the issue. (If you're feeling adventurous, you could clone https://github.com/Nordgedanken/intellij-autohotkey, upgrade mockk to |
Might be fixed by #872 |
When will you release it? |
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 confirm that the problem persists. I updated the demo: |
Seems to be a dedicated problem for java enum classes that implements an interface. |
My case failed with something other than an enum - I was trying to use
The mock stubbing looks like this: every { request.headerNames } returns Collections.enumeration(setOf("a", "b", "c")) |
@realjenius your specific issue seems to be caused by a koltin reflection issue, see KotlinReflectionInternalError: Unresolved class" when inspecting anonymous Java class |
Thank you @qoomon ! I don't want to derail this issue then, but do you have suggestions for a reasonable workaround? This was working with Mockk 1.12.4, is some additional reflection logic causing this? I have a lot of developers that are using this test library in my company and I'm worried If I upgrade this a lot of teams might be impacted that weren't previously. |
@realjenius oh I wasn't aware of the fact that is was working in version |
Probably we need to catch all exceptions
|
#890 should fix it |
can you release it? 🙏 |
This now also happens with 1.12.7 (cf. #884). It worked in 1.12.6, no changes other than upgrading to 1.12.7 and replacing io.mockk with io.mockk-jvm dependency (Maven). Is there an easy workaround? If not can this fix be released soon? Otherwise we are stuck on 1.12.6. |
@stefanzilske can you please try downloading the |
@Raibaz it was still failing with 1.12.8-SNAPSHOT, built from the master branch. Then I noticed that I've got some mockk artifacts also in 1.12.4 on my classpath, because I am also using springmockk in 3.1.1. After excluding So we need an updated version of springmockk, which is built upon mockk:1.12.7 |
That is not necessary, you can just tell gradle to exclude this dependency from springmockk. |
🙏 for release |
Sure, but I am using mockk in 20 or so Maven multi module micro services, so I guess I have 40-60 places where I have to add this exclusion. Incrementing springmockk version along with mockk-jvm would be a lot easier 😉 I will add this as an issue at springmockk! Thanks a lot! |
can we pls release it? |
Just released v1.12.8. |
I am sorry, but this is not resolved - demo build still fails on 1.12.8: https://gitlab.com/knyttl/mockkdemo/-/jobs/3032515325
And:
|
Yeah, still looks broken to me ... 1.12.8. jar is still empty, mockk-jvm is needed. So it's sill highly incompatible with older versions. And all that came with a patch level update 😔 /cc @aSemy |
Thanks for the demo project. This is failing because it's missing an ElasticSearch class. If I change the test to remove it... package tl.knyt
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 =
fun getSchedules(sortOrder: String = "asd"): String =
sortOrder.toString()
} it works. |
@stefanzilske Can you make a new issue with a demo project, or link to open source one please? :) I'm particularly interested in the build config ( |
Of course this works if you use a simple class. My point is exactly that it does not work with this special case – this is the reason I had to use link the external project otherwise I couldn't reproduce it. Also, as I mentioned, this worked correctly until 1.12.4. |
Okay, gotcha. I got confused by others in the thread mentioning the mockk-jvm issue, my bad! I had another look and here's the full stacktrace (the
So it looks like #890 wasn't enough. It also needs to catch |
@aSemy you are right. Because I don't know what kind of exceptions could be throw my initial solution was to catch all throwables. |
@aSemy however we are already catching KotlinReflectionInternalError. It seems KotlinReflectionInternalError can't be catched. |
|
Are you? mockk/modules/mockk-core/src/jvmMain/kotlin/io/mockk/core/ValueClassSupport.kt Lines 61 to 66 in 1f2d038
The isValue_safe exists multiple places, as seen here https://github.com/mockk/mockk/pull/890/files |
so can we reopen this? |
Should be fixed by #922. The extra catch somehow got lost during refactoring or reorganizing the project. |
superb! can we release it then? |
Fixed in 1.13.1 |
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:
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.
Minimal reproducible code (the gist of this issue)
The text was updated successfully, but these errors were encountered: