OtterMind/Chat2DB · critical · RuntimeException

Error creating XML document

Error message

Error creating XML document

What it means

RuntimeException 'Error creating XML document' from XMLUtils.createDocument when DocumentBuilderFactory.newDocumentBuilder fails (ParserConfigurationException). This is a JVM/environment failure to obtain a document builder, not an input error.

Source

Thrown at chat2db-community-server/chat2db-community-domain/chat2db-community-domain-core/src/main/java/ai/chat2db/community/domain/core/impl/ncx/XMLUtils.java:64

            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
            dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
            dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
            dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
            DocumentBuilder xmlBuilder = dbf.newDocumentBuilder();
            return xmlBuilder.parse(source);
        } catch (Exception er) {
            throw new RuntimeException("Error parsing XML document", er);
        }
    }

    public static Document createDocument() {
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder xmlBuilder = dbf.newDocumentBuilder();
            return xmlBuilder.newDocument();
        } catch (Exception er) {
            throw new RuntimeException("Error creating XML document", er);
        }
    }

    public static Element getChildElement(Element element,  String childName) {
        if (element == null) {
            return null;
        }
        for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) {
            if (node.getNodeType() == Node.ELEMENT_NODE &&
                ((Element) node).getTagName().equals(childName)) {
                return (Element) node;
            }
        }
        return null;
    }

    public static String getChildElementBody(Element element,  String childName) {
        if (element == null) {

View on GitHub (pinned to 5ee1e990e7)

Solutions

  1. Ensure a JAXP implementation (JDK default or xerces/dom4j) is on the classpath.
  2. Check/unset javax.xml.parsers.DocumentBuilderFactory overrides.
  3. Resolve XML API version conflicts in the dependency tree.
Defensive patterns

Strategy: try-catch

Validate before calling

// fail fast at startup if JAXP is unavailable
try { DocumentBuilderFactory.newInstance().newDocumentBuilder(); }
catch (ParserConfigurationException e) { throw new IllegalStateException("JAXP DocumentBuilder unavailable", e); }

Try / catch

try { return XMLUtils.createDocument(); }
catch (RuntimeException e) { // Error creating XML document
    throw new IllegalStateException("XML writer unavailable on this JVM/classpath", e);
}

Prevention

When it happens

Trigger: DocumentBuilder cannot be instantiated — typically a misconfigured or missing JAXP implementation on the classpath, or a system property selecting a non-existent factory.

Common situations: A JRE without the default JAXP provider; conflicting XML API jars on classpath; javax.xml.parsers.DocumentBuilderFactory system property pointing at a missing class.

Related errors


AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14). Data as JSON: /api/errors/a7f7297fab3cd442. Report an issue: GitHub.