JDK 16 & InaccessibleObjectException
See original GitHub issueExpected Behavior
I upgraded to JDK16 & Gradle 7 and I have issues when running mockk:
// method for mocking timestamps
fun mockNow(string: String) {
mockkStatic(Instant::class, ZonedDateTime::class, LocalDate::class, LocalDateTime::class)
every { Instant.now() }.returns(instantOf(string))
every { ZonedDateTime.now() }.returns(zonedDateTimeOf(string))
}
mockNow("2020-01-01T12:00:00Z")
Will fail with:
java.time.format.DateTimeParseException: Text '2020-01-01T12:00:00Z' could not be parsed: Unable to make private static java.time.LocalDate java.time.LocalDate.create(int,int,int) accessible: module java.base does not "opens java.time" to unnamed module @7254bd8e
at java.base/java.time.format.DateTimeFormatter.createError(DateTimeFormatter.java:2023)
at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1958)
at java.base/java.time.ZonedDateTime.parse(ZonedDateTime.java:600)
(see full stacktrace below)
Current Behavior
We currently use JDK11 where this works 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.0
- OS: Any
- Kotlin version: 1.5.30-RC
- JDK version: 16
- JUnit version: 5.7.0
- Type of test: unit test
Full stacktrace
java.time.format.DateTimeParseException: Text '2020-01-01T12:00:00Z' could not be parsed: Unable to make private static java.time.LocalDate java.time.LocalDate.create(int,int,int) accessible: module java.base does not "opens java.time" to unnamed module @7254bd8e
at java.base/java.time.format.DateTimeFormatter.createError(DateTimeFormatter.java:2023)
at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1958)
at java.base/java.time.ZonedDateTime.parse(ZonedDateTime.java:600)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at io.mockk.proxy.jvm.advice.MethodCall.call(MethodCall.kt:14)
at io.mockk.proxy.jvm.advice.SelfCallEliminatorCallable.call(SelfCallEliminatorCallable.kt:14)
at io.mockk.impl.instantiation.JvmMockFactoryHelper.handleOriginalCall(JvmMockFactoryHelper.kt:95)
at io.mockk.impl.instantiation.JvmMockFactoryHelper.access$handleOriginalCall(JvmMockFactoryHelper.kt:18)
at io.mockk.impl.instantiation.JvmMockFactoryHelper$mockHandler$1$invocation$$inlined$stdFunctions$lambda$1.invoke(JvmMockFactoryHelper.kt:27)
at io.mockk.impl.stub.MockKStub$handleInvocation$originalPlusToString$1.invoke(MockKStub.kt:230)
at io.mockk.impl.stub.SpyKStub.defaultAnswer(SpyKStub.kt:15)
at io.mockk.impl.stub.MockKStub.answer(MockKStub.kt:42)
at io.mockk.impl.recording.states.AnsweringState.call(AnsweringState.kt:16)
at io.mockk.impl.recording.CommonCallRecorder.call(CommonCallRecorder.kt:53)
at io.mockk.impl.stub.MockKStub.handleInvocation(MockKStub.kt:266)
at io.mockk.impl.instantiation.JvmMockFactoryHelper$mockHandler$1.invocation(JvmMockFactoryHelper.kt:23)
at io.mockk.proxy.jvm.advice.Interceptor.call(Interceptor.kt:21)
at java.base/java.time.ZonedDateTime.parse(ZonedDateTime.java:600)
at java.base/java.time.ZonedDateTime.parse(ZonedDateTime.java:585)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at io.mockk.proxy.jvm.advice.MethodCall.call(MethodCall.kt:14)
at io.mockk.proxy.jvm.advice.SelfCallEliminatorCallable.call(SelfCallEliminatorCallable.kt:14)
at io.mockk.impl.instantiation.JvmMockFactoryHelper.handleOriginalCall(JvmMockFactoryHelper.kt:95)
at io.mockk.impl.instantiation.JvmMockFactoryHelper.access$handleOriginalCall(JvmMockFactoryHelper.kt:18)
at io.mockk.impl.instantiation.JvmMockFactoryHelper$mockHandler$1$invocation$$inlined$stdFunctions$lambda$1.invoke(JvmMockFactoryHelper.kt:27)
at io.mockk.impl.stub.MockKStub$handleInvocation$originalPlusToString$1.invoke(MockKStub.kt:230)
at io.mockk.impl.stub.SpyKStub.defaultAnswer(SpyKStub.kt:15)
at io.mockk.impl.stub.MockKStub.answer(MockKStub.kt:42)
at io.mockk.impl.recording.states.AnsweringState.call(AnsweringState.kt:16)
at io.mockk.impl.recording.CommonCallRecorder.call(CommonCallRecorder.kt:53)
at io.mockk.impl.stub.MockKStub.handleInvocation(MockKStub.kt:266)
at io.mockk.impl.instantiation.JvmMockFactoryHelper$mockHandler$1.invocation(JvmMockFactoryHelper.kt:23)
at io.mockk.proxy.jvm.advice.Interceptor.call(Interceptor.kt:21)
at java.base/java.time.ZonedDateTime.parse(ZonedDateTime.java:585)
at net.goout.instant.InstantUtilsKt.zonedDateTimeOf(InstantUtils.kt:63)
at net.goout.instant.InstantUtilsKt.instantOf(InstantUtils.kt:79)
at net.goout.instant.InstantTestUtilsKt.mockNow(InstantTestUtils.kt:14)
at net.goout.instant.InstantUtilsTest.testMockNow(InstantUtilsTest.kt:24)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:12 (1 by maintainers)
Top Results From Across the Web
InaccessibleObjectException (Java SE 16 & JDK 16)
Constructs an InaccessibleObjectException with the given detail message. Method Summary. Methods declared in class java.lang.Throwable · addSuppressed, ...
Read more >InaccessibleObjectException with JDK 16 · Issue #1875 - GitHub
GSon (2.8.6) has trouble with JDK 16, seemingly due to ... InaccessibleObjectException: Unable to make private java.util.
Read more >How to resolve "InaccessibleObjectException" of jdk16
java, I found cglib is trying to use "defineClass" of "sun.misc.Unsafe". Unfortunately, I can find that class but cannot find that method in...
Read more >Build fails with JDK-16 RC2 (InaccessibleObjectException)
Use the newest EAP Idea and JDK-16 Release candidate 2; Make changes to a project; Run it, triggering an automatic build. What is...
Read more >How to run FisPro with JDK >= 16
The JDK 16 has changed the default access to some java packages to deny – this ... InaccessibleObjectException: Unable to make field protected...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can fix this issue on your own.
To the java Test-Process, add
--add-opens java.base/java.time=ALL-UNNAMED
as start-argument and it’ll work. Here is the corresponding JEP for reference: https://openjdk.java.net/jeps/396If you’d have shared your grade config, as required by the issue-template, I could tell you exactly, but as you did not provide it, you’ll have to figure out where exactly to add it on your own.
This is not a bug in MockK.