MyCATApache/Mycat-Server · error · ConfigException

ConfigException wrapping cause (no message)

Error message

ConfigException wrapping cause (no message)

What it means

XMLSchemaLoader.load catches any non-ConfigException thrown while parsing schema.xml (loadDataHosts, loadDataNodes, loadSchemas) and wraps it in a ConfigException with the original as cause and no message of its own. The real failure reason (XML parse error, NPE, IO problem, DTD issue) is only visible in the wrapped cause's stack trace.

Solutions

  1. Read the full stack trace's 'Caused by' section to find the underlying exception and its line.
  2. Validate schema.xml against its DTD (xmllint --dtdvalid) and fix structural errors.
  3. Temporarily add logging or run in a debugger to find which load* method throws before the wrap point.
  4. Restore a known-good schema.xml and reapply changes incrementally to isolate the offending element.

Example fix

// before (schema.xml)
<schema name="TESTDB">
  <table name="orders" dataNode="dn1" />
<!-- missing closing </schema> -->
// after
<schema name="TESTDB">
  <table name="orders" dataNode="dn1" />
</schema>
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate schema.xml structure before startup
DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
db.setErrorHandler(new DefaultHandler() {
    @Override public void error(SAXParseException e) throws SAXException { throw e; }
});
db.parse(new File("schema.xml")); // throws on malformed XML before MyCat load

Try / catch

try {
    loader = new XMLSchemaLoader();
} catch (ConfigException e) {
    Throwable root = e;
    while (root.getCause() != null) root = root.getCause(); // unwrap to real reason
    LOG.error("schema.xml load failed, root cause:", root);
    throw new IllegalArgumentException("Invalid schema.xml: " + root.getMessage(), e);
}

Prevention

When it happens

Trigger: Any unexpected Exception during XMLSchemaLoader construction: malformed XML, missing required child elements causing NPE inside loadSchemas/loadTables/loadDataNodes, IO errors, ClassCastException; load() rethrows as cause-less-message ConfigException.

Common situations: schema.xml edited with a broken tag or wrong DTD; element attributes missing (getAttribute returning empty string leading to downstream NPE); file encoding problems; upgrades where the DTD no longer matches the XML.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11). Data as JSON: /api/errors/349f16523675b425. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/config/loader/xml/XMLSchemaLoader.java:121

    }

    private void load(String dtdFile, String xmlFile) {
        InputStream dtd = null;
        InputStream xml = null;
        try {
            dtd = XMLSchemaLoader.class.getResourceAsStream(dtdFile);
            xml = XMLSchemaLoader.class.getResourceAsStream(xmlFile);
            Element root = ConfigUtil.getDocument(dtd, xml).getDocumentElement();
            //先加载所有的DataHost
            loadDataHosts(root);
            //再加载所有的DataNode
            loadDataNodes(root);
            //最后加载所有的Schema
            loadSchemas(root);
        } catch (ConfigException e) {
            throw e;
        } catch (Exception e) {
            throw new ConfigException(e);
        } finally {

            if (dtd != null) {
                try {
                    dtd.close();
                } catch (IOException e) {
                }
            }

            if (xml != null) {
                try {
                    xml.close();
                } catch (IOException e) {
                }
            }
        }
    }

View on GitHub (pinned to 65f8d8beb7)