Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Log4j error when using PowerMockRule - Classloader inconsistencies #272

Open
johanhaleby opened this Issue Jul 24, 2015 · 12 comments

Comments

Projects
None yet
1 participant
Collaborator

johanhaleby commented Jul 24, 2015

From loic.lac...@gmail.com on April 12, 2010 11:15:55

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: http://code.google.com/p/powermock/issues/detail?id=252

Collaborator

johanhaleby commented Jul 24, 2015

From johan.ha...@gmail.com on April 12, 2010 03:43:13

Don't you get the same error when running with the PowerMock runner?

Collaborator

johanhaleby commented Jul 24, 2015

From loic.lac...@gmail.com on April 12, 2010 03:44:25

Nope

Collaborator

johanhaleby commented Jul 24, 2015

From johan.ha...@gmail.com on April 12, 2010 03:57:33

Could you help us by providing an example test/project?

Collaborator

johanhaleby commented Jul 24, 2015

From loic.lac...@gmail.com on April 12, 2010 04:10:26

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.

Collaborator

johanhaleby commented Jul 24, 2015

From johan.ha...@gmail.com on April 12, 2010 04:13:27

Could you attach the test and class under test here?

Collaborator

johanhaleby commented Jul 24, 2015

From loic.lac...@gmail.com on April 12, 2010 05:01:32

I'll try to pinpoint the problem ASAP and post the set of problematic classes.

Collaborator

johanhaleby commented Jul 24, 2015

From loic.lac...@gmail.com on April 12, 2010 05:23:54

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.

Attachment: PowerMockIssue.zip

Collaborator

johanhaleby commented Jul 24, 2015

From johan.ha...@gmail.com on April 12, 2010 05:26:47

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

Collaborator

johanhaleby commented Jul 24, 2015

From loic.lac...@gmail.com on April 12, 2010 05:39:55

Here I could reproduce the original issue.

Attachment: PowerMockIssue_originalIssue.zip

Collaborator

johanhaleby commented Jul 24, 2015

From johan.ha...@gmail.com on April 12, 2010 07:10:25

Thanks, hopefully I can have a look at this tomorrow.

Collaborator

johanhaleby commented Jul 24, 2015

From johan.ha...@gmail.com on April 12, 2010 23:26:24

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 :/

Status: Accepted

Collaborator

johanhaleby commented Jul 24, 2015

From loic.lac...@gmail.com on April 21, 2010 09:12:26

I get a JVM crash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment