Thoppan / powermock

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

Log4j error when using PowerMockRule - Classloader inconsistencies #252

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Add PowerMockRule to junit test class
2. Remove PowerMockRunner
3. Run the test

log4j:ERROR A "org.apache.log4j.xml.DOMConfigurator" object is not
assignable to a "org.apache.log4j.spi.Configurator" variable.
log4j:ERROR The class "org.apache.log4j.spi.Configurator" was loaded by 
log4j:ERROR [org.powermock.core.classloader.MockClassLoader@1b09468]
whereas object of type 
log4j:ERROR "org.apache.log4j.xml.DOMConfigurator" was loaded by
[sun.misc.Launcher$AppClassLoader@17172ea].
log4j:ERROR Could not instantiate configurator
[org.apache.log4j.xml.DOMConfigurator].

The problem probably comes from the fact that the test class contains a
logger that is instanciated by the default classloader.  It is a limitation
of the new bootstrapper that should be properly documented.

Original issue reported on code.google.com by loic.lac...@gmail.com on 12 Apr 2010 at 9:15

GoogleCodeExporter commented 9 years ago
Don't you get the same error when running with the PowerMock runner?

Original comment by johan.ha...@gmail.com on 12 Apr 2010 at 10:43

GoogleCodeExporter commented 9 years ago
Nope

Original comment by loic.lac...@gmail.com on 12 Apr 2010 at 10:44

GoogleCodeExporter commented 9 years ago
Could you help us by providing an example test/project?

Original comment by johan.ha...@gmail.com on 12 Apr 2010 at 10:57

GoogleCodeExporter commented 9 years ago
The test class is instanciated by the PowerMockRunner when used, while when the 
PowerMockRule is used, the default classloader is used for the test class. My 
test 
class contains a Logger field which is the core of the problem I found.

Original comment by loic.lac...@gmail.com on 12 Apr 2010 at 11:10

GoogleCodeExporter commented 9 years ago
Could you attach the test and class under test here?

Original comment by johan.ha...@gmail.com on 12 Apr 2010 at 11:13

GoogleCodeExporter commented 9 years ago
I'll try to pinpoint the problem ASAP and post the set of problematic classes.

Original comment by loic.lac...@gmail.com on 12 Apr 2010 at 12:01

GoogleCodeExporter commented 9 years ago
I tried to reduce the problem I spotted to a single class and another problem 
happens. 
I attached a maven project containing both the @RunWith(PowerMockRunner.class) 
and the 
PowerMockRule versions. A NullPointerException is thrown in the PowerMockRule 
version.
I use java 1.6.0_19 win32.

Original comment by loic.lac...@gmail.com on 12 Apr 2010 at 12:23

Attachments:

GoogleCodeExporter commented 9 years ago
The NPE is a known issue which has been resolved in trunk already. Thanks for 
the zip 
though, I'll check it out.

Original comment by johan.ha...@gmail.com on 12 Apr 2010 at 12:26

GoogleCodeExporter commented 9 years ago
Here I could reproduce the original issue.

Original comment by loic.lac...@gmail.com on 12 Apr 2010 at 12:39

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks, hopefully I can have a look at this tomorrow.

Original comment by johan.ha...@gmail.com on 12 Apr 2010 at 2:10

GoogleCodeExporter commented 9 years ago
What error do you get? I get the same print-out when using the PowerMockRunner 
as 
well. How ever I my JVM crash when I'm using the rule :/

Original comment by johan.ha...@gmail.com on 13 Apr 2010 at 6:26

GoogleCodeExporter commented 9 years ago
I get a JVM crash

Original comment by loic.lac...@gmail.com on 21 Apr 2010 at 4:12