0

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);
2
  • 1
    I suspect your xml file references some other files somewhere that cannot be found. Hard to tell without knowing anything about your xml file. Commented Dec 7, 2022 at 10:29
  • 1
    So the XML has <!DOCTYPE preferences SYSTEM "http://java.sun.com/dtd/preferences.dtd"> meaning an XML parser is trying to read http://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. Commented Dec 7, 2022 at 11:04

1 Answer 1

0

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.