My Java application gives a FileNotFoundException when trying to parse an XML file with the SAXParser class. The stack trace is:
java.base/java.io.FileInputStream.open0(Native Method),
java.base/java.io.FileInputStream.open(Unknown Source),
java.base/java.io.FileInputStream.<init>(Unknown Source),
java.base/java.io.FileInputStream.<init>(Unknown Source),
java.base/sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source),
java.base/sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source),
java.xml/com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source),
java.xml/com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(Unknown Source),
java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source),
java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source),
java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source),
java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source),
java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source),
java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source),
java.xml/javax.xml.parsers.SAXParser.parse(Unknown Source)
I ran the application on Windows and on Linux, on Linux I can reproduce it more frequently (I don't know why...). The problem appears to occur randomly and I am sure the file exists and can be read.
IMPLEMENTOR="Eclipse Adoptium"
IMPLEMENTOR_VERSION="Temurin-17.0.2+8"
JAVA_VERSION="17.0.2"
JAVA_VERSION_DATE="2022-01-18"
This link suggests it may be an issue related to permissions: https://community.cloudera.com/t5/Support-Questions/CDF-Add-NiFi-CA-Service-Service-to-Cluster/mp/268975/highlight/true
But that does not work for me.
EDIT: I have pasted the XML file contents here: https://pastebin.com/Q0WE9Y9S
EDIT: I have configured the SAXParserFactory so it does not load external DTD's:
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
factory.setValidating(false);
factory.setNamespaceAware(false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
I have resolved this issue, it was due to another bug in my own code. So it had nothing to do with the SAXParser. Thanks for all the help!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.