question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

java.lang.IllegalAccessError when using PowerMock 1.6.0 and Mockito 1.10.16

See original GitHub issue

From behran…@gmail.com on December 15, 2014 04:39:04

What steps will reproduce the problem? 1. The following test class can reproduce the issue:

@RunWith(PowerMockRunner.class) @PrepareForTest({StringBuilder.class}) public class BugTest {

@Before
public void setUp() throws Exception {
    mockStatic(StringBuilder.class);
}

@Test
public void testSomething() throws Exception {

}

} What is the expected output? What do you see instead? The test fails to run. Instead it breaks with the following stack trace:

java.lang.IllegalAccessError: tried to access class org.mockito.internal.creation.cglib.CGLIBHacker from class org.mockito.internal.creation.MethodInterceptorFilter at org.mockito.internal.creation.MethodInterceptorFilter.<init>(MethodInterceptorFilter.java:34) at org.powermock.api.mockito.internal.mockcreation.PowerMockMethodInterceptorFilter.<init>(PowerMockMethodInterceptorFilter.java:18) at org.powermock.api.mockito.internal.mockcreation.MockCreator.createMethodInvocationControl(MockCreator.java:108) at org.powermock.api.mockito.internal.mockcreation.MockCreator.mock(MockCreator.java:57) at org.powermock.api.mockito.PowerMockito.mockStatic(PowerMockito.java:70) at au.com.sensis.sitesmart.api.v1.AbstractSiteServletTest.setUp(AbstractSiteServletTest.java:31) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at org.junit.internal.runners.MethodRoadie.runBefores(MethodRoadie.java:129) at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:93) at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:294) at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTestInSuper(PowerMockJUnit47RunnerDelegateImpl.java:127) at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTest(PowerMockJUnit47RunnerDelegateImpl.java:82) at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:282) at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84) at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49) at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:207) at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:146) at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:120) at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34) at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44) at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:122) at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:106) at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53) at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59) at org.junit.runner.JUnitCore.run(JUnitCore.java:157) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) What version of the product are you using? On what operating system? PowerMock 1.6.0 with Mockito 1.10.16 using Java 1.7.0_72 on Ubuntu 14.04 64-bit

_Original issue: http://code.google.com/p/powermock/issues/detail?id=533_

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
francovitalicommented, Nov 15, 2016

For the record, we downgraded “mockito-core” version and it worked:

testCompile ‘junit:junit:4.12’ testCompile ‘org.mockito:mockito-core:2.0.42-beta’ testCompile ‘org.powermock:powermock-module-junit4:1.6.6’ testCompile ‘org.powermock:powermock-api-mockito2:1.6.6’

3reactions
Poeschlcommented, Nov 10, 2016

I’m having the same problem with Powermock 1.6.6 and Mockito 2.0.24

    testCompile "junit:junit:4.12"
    testCompile "org.mockito:mockito-core:2.0.42"
    testCompile "org.powermock:powermock-module-junit4:1.6.6"
    testCompile "org.powermock:powermock-api-mockito2:1.6.6"
Read more comments on GitHub >

github_iconTop Results From Across the Web

class org.mockito.Matchers tried to access private method
Using mockito any() throws java.lang.IllegalAccessError: class org.mockito.Matchers tried to access private method · Subscribe to RSS.
Read more >
java.lang.IllegalAccessError: ... cannot access its ...
I'm trying to mock a class with a private interface. ... IllegalAccessError: class ClassToMock$4 cannot access its ... mockStaticPartial(PowerMock.java:579)
Read more >
Liu Chuanshi powermock Issues - Giters
PowerMockito : Mocking two static methods of two different classes breaks the first ... IllegalAccessError when using PowerMock 1.6.0 and Mockito 1.10.16.
Read more >
Incompatibility with mockito 1.10.9 and 1.10.10 #524 - Github Lab
8 with powermock-api-mockito:1.5.6, and it worked fine. I tried upgrading to mockito 1.10.9 and 1.10.10, but I got: java.lang.IllegalAccessError: org/mockito/ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found