We have a plugin named mockito and it has cglib-nodep-2.2.2.jar, hamcrest-core-1.3.jar, mockito-core-1.10.19.jar, objenesis-2.4.jar, jmockit-1.49.jar in it’s bundle-classpath and have exported all the packages from all the jar files for consumption by other bundles. The ‘automatic module name’ is set to mockito
.
We are currently in plan to migrate from eclipse 4.16 and Java 11 to eclipse 4.27 and java 17 respectively.
In one of the test case plugin, mockito bundle is imported and Test Class creates a mocked IProject by IProject project = Mockito.mock(IProject.class);
. While running the test it is failing with error java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @738e057b 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 org.mockito.cglib.core.ReflectUtils$2.run(ReflectUtils.java:57) at java.base/java.security.AccessController.doPrivileged(AccessController.java:318) at org.mockito.cglib.core.ReflectUtils.<clinit>(ReflectUtils.java:47) at org.mockito.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:167) at org.mockito.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25) at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:217) at org.mockito.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145) at org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:117) at org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:109) at org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:105) at org.mockito.cglib.proxy.Enhancer.<clinit>(Enhancer.java:70) at org.mockito.internal.creation.cglib.ClassImposterizer.createProxyClass(ClassImposterizer.java:95) at org.mockito.internal.creation.cglib.ClassImposterizer.imposterise(ClassImposterizer.java:57) at org.mockito.internal.creation.cglib.ClassImposterizer.imposterise(ClassImposterizer.java:49) at org.mockito.internal.creation.cglib.CglibMockMaker.createMock(CglibMockMaker.java:24) at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:33) at org.mockito.internal.MockitoCore.mock(MockitoCore.java:59) at org.mockito.Mockito.mock(Mockito.java:1285) at org.mockito.Mockito.mock(Mockito.java:1163)
Other options tried:
- I also moved all the jars from classpath to modulepath and edited the Manifest.MF of each jar and introduced Automatic-module-Name (eg.Automatic-Module-Name: cglib.nodep). But, still I get the same error.
Shouldn’t the module be named because ‘Automatic Module name’ is set in Manifest.MF?
The consideration of --add-opens java.lang==ALL-UNNAMED
is not possible, as it would open the packages for all unnamed modules.
How to resolve this issue and open the packages java.lang package for access to mockito bundle?
How to do it the right way?
Thanks,
Pal
5