Navigation Menu

Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

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
Open

Comments

@johanhaleby
Copy link
Collaborator

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

@johanhaleby
Copy link
Collaborator Author

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?

@johanhaleby
Copy link
Collaborator Author

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

Nope

@johanhaleby
Copy link
Collaborator Author

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

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

@johanhaleby
Copy link
Collaborator Author

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.

@johanhaleby
Copy link
Collaborator Author

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

Could you attach the test and class under test here?

@johanhaleby
Copy link
Collaborator Author

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.

@johanhaleby
Copy link
Collaborator Author

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

@johanhaleby
Copy link
Collaborator Author

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.

@johanhaleby
Copy link
Collaborator Author

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

Here I could reproduce the original issue.

Attachment: PowerMockIssue_originalIssue.zip

@johanhaleby
Copy link
Collaborator Author

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

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

@johanhaleby
Copy link
Collaborator Author

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

@johanhaleby
Copy link
Collaborator Author

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
Projects
None yet
Development

No branches or pull requests

1 participant