Search code examples
javajunitjaxbpowermockpowermockito

Linkage error while using Powerclass for test class that uses JAXB


`java.lang.LinkageError: loader constraint violation: when resolving overridden method "com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshal

`Exception(Lorg/xml/sax/SAXException;)Ljavax/xml/bind/UnmarshalException;" the class loader (instance of org/powermock/core/classloader/MockClassLoader) of the current class, com/sun/xml/bind/v2/runtime/unmarshaller/UnmarshallerImpl, and its superclass loader (instance of <bootloader>), have different Class objects for the type org/xml/sax/SAXException used in the signature

I am using Powermock for mocking static class in JUNIT test case. Since my junit uses xml files, I was getting few errors and I have to use powermock ignore like below.

@PowerMockIgnore({ "javax.xml.*"})
@RunWith(PowerMockRunner.class)

I get the linkage error along with the below error . Please advise

javax.xml.transform.TransformerFactoryConfigurationError: Provider for class javax.xml.transform.TransformerFactory cannot be created

Solution

  • Issue resolved after I used all the three imports inside powermockignore

    @PowerMockIgnore({
            "javax.xml.*",
            "org.xml.*",
            "org.w3c.*"
    })