I am using Powermockito to mock and spy static classes. Version: 2.0.4
Also using mockito-core version 3.0.0.
In, one of my projects, i am able to mockStatic by enabling mock-maker-inline as specified here
But, when i tried the same approach on my another project, facing the following error:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.ghx.tpm.api.ISubscribedProductParameterService]: Factory method 'subscribedProductParameterService' threw exception; nested exception is java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null) Caused by: java.lang.IllegalStateException: Could not initialize plugin: interface org.mockito.plugins.MockMaker (alternate: null) Caused by: java.lang.IllegalStateException: Failed to load interface org.mockito.plugins.MockMaker implementation declared in sun.misc.CompoundEnumeration@614aeccc Caused by: java.lang.IllegalStateException: Failed to load MockMaker implementation: mock-maker-inline Caused by: java.lang.IllegalStateException: Internal problem occurred, please report it. Mockito is unable to load the default implementation of class that is a part of Mockito distribution. Failed to load interface org.mockito.plugins.MockMaker Caused by: org.mockito.exceptions.base.MockitoInitializationException: Could not initialize inline Byte Buddy mock maker. (This mock maker is not supported on Android.) Java : 1.8 JVM vendor name : Oracle Corporation JVM vendor version : 25.161-b12 JVM name : Java HotSpot(TM) 64-Bit Server VM JVM version : 1.8.0_161-b12 JVM info : mixed mode OS name : Linux OS version : 4.4.0-166-generic Caused by: java.lang.IllegalStateException: Error during attachment using: net.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound@3c89bb12 Caused by: java.lang.reflect.InvocationTargetException Caused by: java.lang.NullPointerException
Can you please help in resolving this issue?
- I am mocking static spy class here.
- byte-buddy jar resolved dependency version is 1.9.10
- will overlap of mockito2 and powermock-api-mockito2 will cause issue in loading MockMaker? how to resolve them?
- If the test is executed in IDE it is working fine. but fails when run in maven console.
Ensured JavassistMockClassLoader is used by adding @PrepareForTest and PowerMockRunner (since one of my other project worked with same configuration)
Facing Null pointer Exception exactly at this line:
ByteBuddyAgent.java (private static void install(AttachmentProvider attachmentProvider, String processId, String argument, AgentProvider agentProvider) Attacher.install(attachmentAccessor.getVirtualMachineType(), processId, agentProvider.resolve().getAbsolutePath(), argument);
Classloader while it is failing is – AppLaunchClassLoader. ( Whereas for working project it is URLClassLoader). Not sure if this difference could be a reason.