-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Hello!
We [1] have been using Mockito with JDK's SecurityManager
(for historical reasons), the things worked fine for us till Mockito 4.8.0
release (and later versions). The culprit is Java9PlusLocationImpl
(see please stack trace below):
Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessDeclaredMembers")
at java.base/java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
at java.base/java.security.AccessController.checkPermission(AccessController.java:897)
at java.base/java.lang.SecurityManager.checkPermission(SecurityManager.java:322)
at java.base/java.lang.Class.checkMemberAccess(Class.java:2847)
at java.base/java.lang.Class.getDeclaredMethod(Class.java:2471)
at org.mockito.internal.debugging.Java9PlusLocationImpl.stackWalker(Java9PlusLocationImpl.java:191)
at org.mockito.internal.debugging.Java9PlusLocationImpl.<clinit>(Java9PlusLocationImpl.java:50)
... 47 more
By all means, Mockito
should know nothing about SecurityManager
and the way we implemented mocking under SecurityManager
is by using Mockito
's extensibility model - plugins (primary, MockMaker
). Sadly for LocationFactory
/ Location
there is no such plugin available so we are stuck on 4.7.x release line. If such plugin would have been available, we could provide privileged implementation for reflection calls. Alternatively, wrapping up Java 9 implementation into multi-release JAR (and getting rid of reflection), would have helped.
We are happy to submit the pull request with either solution, but it would be helpful to know if there is an interest addressing this issue in general, and preferred approach in particular:
- plugin for
LocationFactory
/Location
- multi-release JAR for Java 9
Thank you.
- The mockito message in the stacktrace have useful information, but it didn't help
- The problematic code (if that's possible) is copied here;
Note that some configuration are impossible to mock via Mockito - Provide versions (mockito / jdk / os / any other relevant information)
- Provide a Short, Self Contained, Correct (Compilable), Example of the issue
(same as any question on stackoverflow.com) - Read the contributing guide