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 Spying and Mocking HashMaps on JDK 16+ #864

Open
aSemy opened this issue Jul 26, 2022 · 2 comments
Open

Support Spying and Mocking HashMaps on JDK 16+ #864

aSemy opened this issue Jul 26, 2022 · 2 comments

Comments

@aSemy
Copy link
Contributor

aSemy commented Jul 26, 2022

The tests in HashMapMockTest.kt fail on more recent (16+) JDK versions.

@Test
@Disabled("Does not work anymore with jdk 16+")
fun concurrentHashMap_shouldBeSpied_Successfully() {
val map = spyk(ConcurrentHashMap<String, String>())
assertDoesNotThrow { map.put("key", "value") }
verify(exactly = 1) { map.put("key", "value") }
}

https://github.com/mockk/mockk/runs/7519107510?check_suite_focus=true#step:7:393

HashMapMockTest > concurrentHashMap_shouldBeSpied_Successfully() FAILED
    java.lang.IllegalAccessException: class io.mockk.impl.InternalPlatform cannot access a member of class java.util.concurrent.ConcurrentHashMap (in module java.base) with modifiers "transient volatile"
        at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:[392])
        at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:674)
        at java.base/java.lang.reflect.Field.checkAccess(Field.java:1102)
        at java.base/java.lang.reflect.Field.get(Field.java:423)
        at io.mockk.impl.InternalPlatform.copyFields$copy(InternalPlatform.kt:114)
        at io.mockk.impl.InternalPlatform.copyFields(InternalPlatform.kt:121)
        at io.mockk.impl.instantiation.AbstractMockFactory.spyk(AbstractMockFactory.kt:107)
        at io.mockk.jvm.HashMapMockTest.concurrentHashMap_shouldBeSpied_Successfully(HashMapMockTest.kt:126)

This was discovered in #444 (comment) and #829.

For now, so I can make progress on #863, I've disabled the tests on JDK16+. I'm making this issue to link in the source code.

@stale
Copy link

stale bot commented Nov 2, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If you are sure that this issue is important and should not be marked as stale just ask to put an important label.

@omerates760
Copy link

@aSemy Hi, The problem continues. Is there an update?

@stale stale bot removed the stale label Sep 15, 2023
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

2 participants