3

Note: This error has already been discussed here and various solutions also have been suggested to get rid of jars that conflicts with java-8's default implementation.

My question is an extension to that problem.

For the sake of completeness, here is the stacktrace that i am also facing, when i run the code with java-8:

Feb 29, 2016 12:06:41 PM com.sun.xml.internal.bind.v2.util.XmlFactory createParserFactory
SEVERE: null
org.xml.sax.SAXNotRecognizedException: http://javax.xml.XMLConstants/feature/secure-processing
    at org.apache.xerces.parsers.AbstractSAXParser.setFeature(AbstractSAXParser.java:1487)
    at org.apache.xerces.jaxp.SAXParserImpl.setFeatures(SAXParserImpl.java:145)
    at org.apache.xerces.jaxp.SAXParserImpl.<init>(SAXParserImpl.java:128)
    at org.apache.xerces.jaxp.SAXParserFactoryImpl.newSAXParserImpl(SAXParserFactoryImpl.java:112)
    at org.apache.xerces.jaxp.SAXParserFactoryImpl.setFeature(SAXParserFactoryImpl.java:140)
    at com.sun.xml.internal.bind.v2.util.XmlFactory.createParserFactory(XmlFactory.java:121)
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.getXMLReader(UnmarshallerImpl.java:139)
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:276)

To prove that conflicting jar(s) are indeed the problem (as described in the link shared earlier), I did pull out the relevant code into a different project and successfully ran the code using java-8 (i.e. without any errors) with bare minimum number of jars. So far so good.

And now the query:

In my case, my legacy project uses about 2-3 known conflicting jars used for various reasons. However, there is this new module which uses annotation driven jaxb for oxm processing.

The problem is : I can not get rid of those old and conflicting jars as that pretty much makes 10% of the codebase uncompilable. However, at the same time, i do not wish to get rid of the jaxb/oxm implementation in the new module as well.

Is there a way by which i can somehow tell JVM to ignore old jars and to use the default implementation that is shipped with java-8 whenever the code execution goes through this new module?

Community
  • 1
  • 1
MiKu
  • 385
  • 1
  • 5
  • 16

2 Answers2

10

An alternative approach could be to use the StAX parser to get the XML as an XMLStreamReader and then have JAXB unmarshal that.

XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(reader);
unmarshaller.unmarshal(xmlStreamReader);
bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • 1
    that did solve the problem! Thanks a ton. :) Out of curiosity, i have one more query. Is it not possible to tell JVM (perhaps through some system property or some other means) to use the compatible/right variant of the SAX parser (assuming that is indeed what was causing issues!) out of all the available ones on the classpath? – MiKu Mar 01 '16 at 05:13
0

Had exactly the same issue! Solution worked for me too. Note for the reader, I used FileReader to read an xml file which was unmarshalled fine.