'LinkageError: loading constraint violation when overriding method javax/xml/stream/XMLInputFactory.createXMLEventReader

I'm upgrading an application that's hosted on WebSphere 9 running IBM JDK 8 from Spring 4.0.3 to 5.3.18. While doing so I updated the project's Jackson, Woodstox, and Stax2 dependencies to their latest versions. The application builds, but on startup while converting an XML string to JSON this error occurs:

java.lang.LinkageError: loading constraint violation when overriding method "javax/xml/stream/XMLInputFactory.createXMLEventReader(Ljavax/xml/transform/Source;)Ljavax/xml/stream/XMLEventReader;" during creation of class "com/ctc/wstx/stax/WstxInputFactory": loader "com/ibm/ws/classloader/CompoundClassLoader@c586bf67" of class "com/ctc/wstx/stax/WstxInputFactory" and loader "com/ibm/oti/vm/BootstrapClassLoader@8a89d546" of class "javax/xml/stream/XMLInputFactory" have different types for the method signature
at java.lang.ClassLoader.defineClassImpl(Native Method) ~[?:2.9 (11-06-2019)]
at java.lang.ClassLoader.defineClassInternal(ClassLoader.java:397) ~[?:2.9 (11-06-2019)]
at java.lang.ClassLoader.defineClass(ClassLoader.java:358) ~[?:2.9 (11-06-2019)]
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:154) ~[?:1.8.0]
at com.ibm.ws.classloader.CompoundClassLoader._defineClass(CompoundClassLoader.java:876) ~[com.ibm.ws.runtime.jar:WAS90.SERV1 [f5021945.01]]
at com.ibm.ws.classloader.CompoundClassLoader.localFindClass(CompoundClassLoader.java:754) ~[com.ibm.ws.runtime.jar:WAS90.SERV1 [f5021945.01]]
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:622) ~[com.ibm.ws.runtime.jar:WAS90.SERV1 [f5021945.01]]
at java.lang.ClassLoader.loadClass(ClassLoader.java:871) ~[?:2.9 (11-06-2019)]
at java.lang.Class.forNameImpl(Native Method) ~[?:2.9 (11-06-2019)]
at java.lang.Class.forName(Class.java:403) ~[?:2.9 (11-06-2019)]
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:381) ~[?:1.8.0]
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:415) ~[?:1.8.0]
at java.util.ServiceLoader$1.next(ServiceLoader.java:491) ~[?:1.8.0]
at javax.xml.stream.FactoryFinder.findServiceProvider(Unknown Source) ~[?:?]
at javax.xml.stream.FactoryFinder.find(Unknown Source) ~[?:?]
at javax.xml.stream.XMLInputFactory.newFactory(Unknown Source) ~[?:?]
at com.fasterxml.jackson.dataformat.xml.XmlFactory.<init>(XmlFactory.java:115) ~[jackson-dataformat-xml-2.13.2.jar:2.13.2]
at com.fasterxml.jackson.dataformat.xml.XmlFactory.<init>(XmlFactory.java:101) ~[jackson-dataformat-xml-2.13.2.jar:2.13.2]
at com.fasterxml.jackson.dataformat.xml.XmlFactory.<init>(XmlFactory.java:85) ~[jackson-dataformat-xml-2.13.2.jar:2.13.2]
at com.fasterxml.jackson.dataformat.xml.XmlMapper.<init>(XmlMapper.java:127) ~[jackson-dataformat-xml-2.13.2.jar:2.13.2]

I don't understand the cause of this error. Earlier on in the upgrade I ran into different LinkageErrors that were resolved by removing dependencies which are no longer used by Jackson (jsr173_api, stax-api, and wstx-asl) but I have been unable to resolve this one.



Solution 1:[1]

I kind of faced same issue and solved it in following way, the error shows duplicate "XMLInputFactory" class might be present in different dependencies from application included dependencies or server dependencies or in both.

if possible remove duplicate dependencies from application if not possible at least make dependencies scope that are having class "XMLInputFactory" same either "provided" or "compile".

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chandra_S