'ILLegalAccessError tried to access method org.mockito.internal.handler.MockHandlerFactory

I am trying to mock a static method of InetAddress class using PowerMockito but I am getting the below error IllegalAccessError: Tried to access method org.mockito.internal.handler.MockHandlerFactory.()V from class org.powermock.api.mockito.internal.mockcreation.MockCreator I am not sue if I am doing the right thing. Appreciate any help! Here is my ActualClass

class ActaulClass{

public static someMethod(){
 try{
       //Below line I am trying to mock
    String result = InetAddress.gtLocalHost().getHostName();
       //Some other logic
}catch(Exception e){

}

}

}

Test Class:

@RunWith(PowerMockRUnner.class)
@PrepareForTest(value = {InetAddress.class,ActualClass.class})
class ActualTestClass{
@Test
void  testMethod(){
  //This is where I see the error
   PowerMockito.mockStatic(InetAddress.class); 
   PowerMockito.when(InetAddress.getLocalHost()).thenThrow(new UnknownHostException());
}
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source