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

Add module-info #815

Open
3 tasks done
strowk opened this issue Apr 29, 2022 · 3 comments
Open
3 tasks done

Add module-info #815

strowk opened this issue Apr 29, 2022 · 3 comments

Comments

@strowk
Copy link

strowk commented Apr 29, 2022

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • I am running the latest version
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed

Expected Behavior

I need this library to correctly describe named Java module. This is required, so we could allow it to do some unsafe reflective stuff to other Java modules using option "--add-opens". There is a way to grant it like this --add-opens java.base/java.time=ALL-UNNAMED , however I would prefer to do something like that --add-opens java.base/java.time=io.mockk , so that when tests are running we would not get InaccessibleObjectException , but the bypass is only added for mockk and not anything else.

Current Behavior

Initially I have got this issue, when following happened:

java.lang.reflect.InaccessibleObjectException: Unable to make private static int java.time.OffsetDateTime.compareInstant(java.time.OffsetDateTime,java.time.OffsetDateTime) accessible: module java.base does not "opens java.time" to unnamed module @6ea6d14e
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
	at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
	at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
	at io.mockk.proxy.jvm.advice.MethodCall.call(MethodCall.kt:13)
	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$1$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.OffsetDateTime.compareInstant(OffsetDateTime.java:182)
	at java.base/java.time.OffsetDateTime.compareTo(OffsetDateTime.java:1810)

I'm not entirely sure why compareInstant is even intercepted like that. It also happens kinda random, depends on whether or not other tests executed or not. However I would like to instead of trying to figure this out, just grant mockk a blanket access, but not too wide.

In order to do this mockk has to name the module, because at the time error message says

module java.base does not "opens java.time" to unnamed module @6ea6d14e
, which basically mean that java defined module, but it is unnamed and the only way to refer to it is with "ALL-UNNAMED".

See this: https://docs.gradle.org/current/samples/sample_java_modules_multi_project.html

FYI: I don't believe this is a bug per-se. Library just did not adapt to the newest JDK requirements yet, but it has to at some point, so I would treat this as a feature

@Raibaz
Copy link
Collaborator

Raibaz commented May 1, 2022

Right, makes sense.

@stale
Copy link

stale bot commented Jul 10, 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.

@stale stale bot added the stale label Jul 10, 2022
@wilerson
Copy link

Gradle 7.5 removed implicit opening of modules java.base/java.util and java.base/java.lang. I've started getting InaccessibleObjectException due to a MockkStatic on java.util.UUID.

Just like @strowk reported, we can get around that adding --add-opens java.base/java.util=ALL-UNNAMED, but it would be better to open the module to Mockk only.

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

No branches or pull requests

3 participants