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.
- JRE release details:
IMPLEMENTOR="Eclipse Adoptium"
IMPLEMENTOR_VERSION="Temurin-17.0.2+8"
JAVA_VERSION="17.0.2"
JAVA_VERSION_DATE="2022-01-18"
- I checked and removed any redundant SAXParser classes from the classpath.
- I tried different folders as the file source folder (local, samba share).
- I tried with file permissions set to 777.
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/m-p/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);
<!DOCTYPE preferences SYSTEM "http://java.sun.com/dtd/preferences.dtd">meaning an XML parser is trying to readhttp://java.sun.com/dtd/preferences.dtd. How reliable is that? With similar references to e.g. W3C XHTML DTDs people are usually advised to use a catalogue referencing a local copy to the DTDs as the public server might be stalling to cope with too many requests.