10

I am using powermock with powermock-easymock-1.5-full.jar. The following exception occurs.

These are the all jars i have in my classpath. And are downloaded as powermock package from http://code.google.com/p/powermock/downloads/detail?name=powermock-easymock-testng-1.5.zip&can=2&q=

  1. easymock-3.1.jar
  2. javassist-3.17.1-GA.jar
  3. jcommander-1.27.jar
  4. objenesis-1.2.jar
  5. snakeyaml-1.6.jar
  6. testng-6.8.jar
  7. bsh-2.0b4.jar
  8. cglib-nodep-2.2.2.jar
  9. powermock-easymock-1.5-full.jar

    java.lang.ClassCastException: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl cannot be cast to javax.xml.parsers.DocumentBuilderFactory
    at javax.xml.parsers.DocumentBuilderFactory.newInstance(Unknown Source)
    at com.eibus.localization.message.MessageSet._tryGetMessageText(MessageSet.java:268)
    at com.eibus.localization.message.Message._tryGetMessage(Message.java:135)
    at com.eibus.localization.message.Message.getMessage(Message.java:110)
    at com.eibus.localization.message.Message.getMessageWithLocaleFallBack(Message.java:155)
    at com.eibus.localization.StringFormatter.getMessageWithFallBack(StringFormatter.java:141)
    at com.eibus.localization.StringFormatter.format(StringFormatter.java:43)
    at com.eibus.localization.LocalizableComposite.getMessage(LocalizableComposite.java:42)
    at com.eibus.localization.exception.LocalizableException.getMessage(LocalizableException.java:168)
    at com.eibus.localization.exception.LocalizableException.getLocalizedMessage(LocalizableException.java:130)
    at java.lang.Throwable.toString(Throwable.java:479)
    at java.lang.String.valueOf(Unknown Source)
    at java.io.PrintWriter.println(Unknown Source)
    at java.lang.Throwable$WrappedPrintWriter.println(Unknown Source)
    at java.lang.Throwable.printStackTrace(Throwable.java:654)
    at java.lang.Throwable.printStackTrace(Throwable.java:720)
    at org.junit.runner.notification.Failure.getTrace(Failure.java:67)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestListener.testFailure(JUnit4TestListener.java:68)
    at org.junit.runner.notification.RunNotifier$4.notifyListener(RunNotifier.java:100)
    at org.junit.runner.notification.RunNotifier$SafeNotifier.run(RunNotifier.java:41)
    at org.junit.runner.notification.RunNotifier.fireTestFailure(RunNotifier.java:97)
    at org.junit.internal.runners.MethodRoadie.addFailure(MethodRoadie.java:154)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.handleException(PowerMockJUnit44RunnerDelegateImpl.java:359)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit49RunnerDelegateImpl$PowerMockJUnit49MethodRunner.executeTest(PowerMockJUnit49RunnerDelegateImpl.java:93)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:284)
    at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84)
    at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:209)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:148)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:122)
    at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
    at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:120)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:101)
    at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
    at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:53)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Please help me

1
  • did u get any solution?
    – Saurabh
    May 15, 2014 at 8:01

6 Answers 6

16

Here is something that worked for me:

@PowerMockIgnore({"javax.xml.*", "org.xml.sax.*", "org.w3c.dom.*",  "org.springframework.context.*", "org.apache.log4j.*"}) 
5

If this is a PowerMock related problem, then you can try to annotate you test class with:

@PowerMockIgnore({"javax.xml.parsers.*", "com.sun.org.apache.xerces.internal.jaxp.*"})
2
  • The above trick is not working for me. The interesting part is I get the above exception only when there is a problem(which can through some exception) in my test code. Instead of throwing actual exception it is always throwing the above ClassCastException.
    – Ramesh
    Feb 5, 2013 at 11:42
  • The exception is thrown when log4j is invoked. it's not really related with exceptions
    – cattox
    Apr 16, 2015 at 17:54
0

You can ignore the log4j.. I have the same problem with jptool logger. And I already resolved by ignoring it Here is my code @PowerMockIgnore({"jptools."})

0

This is a PowerMock problem, I had this error:

java.lang.ClassCastException: class sun.security.provider.ConfigFile

that you can resolve with this annotation, try to annotate you test class with :

@PowerMockIgnore({"javax.management.*", "java.lang.*", "javax.security.*" })
0

You can create a configuration.properties file in test/resources/org/powermock/extensions/ with content:

powermock.global-ignore=org.apache.xerces.*,javax.xml.parsers.*,org.xml.sax.*

Note: Comma separation and NO spaces in the property value, otherwise, it will not work! The list of packages depends on the dependencies of your project.

PowerMock Configuration here.

0

I had a similar issue with PowerMock v1.5.1 and Log4j 2.19.0

To fix it, I added org.apache.logging.logj4.* to my existing @PowerMockIgnore annotation like so:

@PowerMockIgnore({"javax.management.*", "org.apache.logging.log4j.*"})
-- Irrelevant annotations removed for brevity --
public class DeclarationRulesDelegateTest extends RulesTest {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.