Mockito + PowerMock LinkageError while mocking system class Mockito + PowerMock LinkageError while mocking system class java java

Mockito + PowerMock LinkageError while mocking system class


Try adding this annotation to your Test class:

@PowerMockIgnore("javax.management.*")

Worked for me.


Similar to the accepted response here, I ended up having to exclude all of the SSL related classes:

@PowerMockIgnore({"javax.management.*", "org.apache.http.conn.ssl.*", "com.amazonaws.http.conn.ssl.*", "javax.net.ssl.*"})

Adding that to the top of my class resolved the error.


Classloader conflict, use this: @PowerMockIgnore("javax.management.*")

Let mock classloader do not load javax.*.It works.