vijayjcp / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 2 forks source link

powermock throws loader constraint violation error:when resolving method "org.apache.log4j.LogManager.getLogger #535

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.used powermock-mockito-1.4.10-full.jar for testing demo code
2.
@RunWith(PowerMockRunner.class)
@PrepareForTest({DemoUtilities.class})

@PowerMockIgnore( 
{"javax.management.*","org.apache.commons.logging.*","org.apache.log4j.*"}) 
public class TestDemoCalculatorA {

    @Rule
    public PowerMockRule rule = new PowerMockRule();

    @Before
    public void setupBeforeTest() throws MocaException{
        _objectFactory = Mockito.mock(DemoObjectFactory.class);
        Mockito.when(_objectFactory.getJobCode(1)).thenReturn(_DemoCode);
        Mockito.when(_objectFactory.getShift(1)).thenReturn(_shift);

        _calculator = Mockito.spy(new DemoCalculatorImpl());
        PowerMockito.mockStatic(DemoUtilities.class);

        _currentDiscrete= Mockito.mock(DemoDiscrete.class);
        _toDiscrete=Mockito.mock(DemoDiscrete.class);
        _fromDiscrete=Mockito.mock(DemoDiscrete.class);
        _demoSummaryRecord=Mockito.mock(DemoSummary.class);
        _demoRecord=Mockito.mock(DemoReadOnly.class);
    }

    /**
     * Tests that false is returned from needToDemo 
     */
    @Test
    public void needToDemo_Starting_Move_Returns_false() {

        String previousMachineId=null;
        String previousSlotId=null;
        DemoDiscrete previousDiscrete = Mockito.mock(DemoDiscrete.class);
        //Set conditions
        Mockito.when(_currentDiscrete.getClientSlotId()).thenReturn("");       
        assertFalse(_calculator.needToDemoTravel());
    }
3.

What is the expected output? What do you see instead?
Test has to pass without errors

Below error is shown in junit logs
<error message="loader constraint violation: when resolving method 
"org.apache.log4j.LogManager.getLogger(Ljava/lang/Class;)Lorg/apache/log4j/Logge
r;" the class loader (instance of 
org/powermock/core/classloader/MockClassLoader) of the current class, 
com/redprairie/moca/server/log/lookup/MocaLookup, and the class loader 
(instance of sun/misc/Launcher$AppClassLoader) for resolved class, 
org/apache/log4j/LogManager, have different Class objects for the type 
ger.getLogger(Ljava/lang/Class;)Lorg/apache/log4j/Logger; used in the 
signature" type="java.lang.LinkageError">java.lang.LinkageError: loader 
constraint violation: when resolving method 
"org.apache.log4j.LogManager.getLogger(Ljava/lang/Class;)Lorg/apache/log4j/Logge
r;" the class loader (instance of 
org/powermock/core/classloader/MockClassLoader) of the current class, 
com/redprairie/moca/server/log/lookup/MocaLookup, and the class loader 
(instance of sun/misc/Launcher$AppClassLoader) for resolved class, 
org/apache/log4j/LogManager, have different Class objects for the type 
ger.getLogger(Ljava/lang/Class;)Lorg/apache/log4j/Logger; used in the signature

What version of the product are you using? On what operating system?

powermock-mockito-1.4.10-full.jar on Windows 7

Please provide any additional information below.

Tried with powermock-mockito-1.6.0-full.jar also, test case fails with 
classloader violation error.

Followed steps in below link, still class loader error is thrown.
https://code.google.com/p/powermock/wiki/FAQ, section 5

Please advice, is there any workaround or fix for this classloader problem.

 Thank you
 Raj

Original issue reported on code.google.com by rajeshda...@gmail.com on 30 Dec 2014 at 5:53

GoogleCodeExporter commented 8 years ago
 I changed PowerMockIgnore from 

@PowerMockIgnore( 
{"javax.management.*","org.apache.commons.logging.*","org.apache.log4j.*"}) 

to 

@PowerMockIgnore( {"javax.management.*"}) 

getting below error, tried using powermock-mockito-1.6.0-full.jar, still below 
error it shows.

java.lang.OutOfMemoryError: PermGen space
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:635)
    at org.powermock.core.classloader.MockClassLoader.loadUnmockedClass(MockClassLoader.java:189)
    at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:147)
    at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:65)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:635)
    at org.powermock.core.classloader.MockClassLoader.loadUnmockedClass(MockClassLoader.java:189)
    at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:147)
    at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:65)

Original comment by rajeshda...@gmail.com on 20 Jan 2015 at 4:54

GoogleCodeExporter commented 8 years ago
After adding the javax.management, running the junit is extremely slow.

Original comment by meen...@gmail.com on 30 Mar 2015 at 6:02