stanfordnlp/CoreNLP · error · SAXParseException

Fatal Error

Error message

Fatal Error

What it means

XMLUtils' SAXErrorHandler re-throws any fatal SAX parsing error as a SAXParseException with an enriched, human-readable message produced by makeBetterErrorString. The library deliberately escalates fatal errors (which SAX parsers otherwise swallow) so XML parsing stops immediately on unrecoverable document problems. It signals a malformed or unreadable XML document rather than a library bug.

Solutions

  1. Open the XML at the reported line/column and fix the well-formedness violation
  2. Re-download or regenerate the XML resource and verify its checksum
  3. Validate the file with xmllint or an XML-aware editor before loading
  4. If the input is HTML or tag-soup, run it through a tolerant parser (e.g. Jsoup) instead of a strict SAX parser

Example fix

// before
Document d = XMLUtils.readDocumentFromFile("model.xml");
// after
File f = new File("model.xml");
if (!f.exists() || f.length() == 0) throw new IOException("model.xml missing/empty");
Process p = new ProcessBuilder("xmllint", "--noout", f.getPath()).start();
if (p.waitFor() != 0) throw new IOException("model.xml is not well-formed");
Document d = XMLUtils.readDocumentFromFile(f.getPath());
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-validate XML well-formedness
try {
  javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File("model.xml"));
} catch (org.xml.sax.SAXParseException e) {
  throw new IOException("model.xml malformed at " + e.getLineNumber() + ":" + e.getColumnNumber(), e);
}

Try / catch

try {
  Document d = XMLUtils.readDocumentFromFile("model.xml");
} catch (SAXParseException e) {
  log.error("XML fatal error: {} at line {} col {}", e.getMessage(), e.getLineNumber(), e.getColumnNumber());
  // repair or re-fetch the resource before retrying
}

Prevention

When it happens

Trigger: Calling XMLUtils parsing helpers (e.g. readDocumentFromStdin / XMLUtils.parse helpers that install SAXErrorHandler) on XML containing a well-formedness violation: unclosed tags, mismatched elements, invalid entity references, encoding errors, or truncated XML.

Common situations: Parsing a model/grammar file that was truncated during download; feeding HTML (not well-formed XML) into an XML parser; wrong file encoding (e.g. UTF-8 bytes read as another charset); hand-edited XML configs with typos.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/d4fb96444ac32859. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/util/XMLUtils.java:1274

        sb.append(" in entity from publicID ").append(ex.getPublicId());
      }
      sb.append('.');
      return sb.toString();
    }

    @Override
    public void warning(SAXParseException exception) {
      log.warn(makeBetterErrorString("Warning", exception));
    }

    @Override
    public void error(SAXParseException exception) {
      log.error(makeBetterErrorString("Error", exception));
    }

    @Override
    public void fatalError(SAXParseException ex) throws SAXParseException {
      throw new SAXParseException(makeBetterErrorString("Fatal Error", ex),
              ex.getPublicId(), ex.getSystemId(), ex.getLineNumber(), ex.getColumnNumber());
      // throw new RuntimeException(makeBetterErrorString("Fatal Error", ex));
    }

  } // end class SAXErrorHandler

  public static Document readDocumentFromString(String s) throws ParserConfigurationException, SAXException {
    InputSource in = new InputSource(new StringReader(s));
    DocumentBuilderFactory factory = safeDocumentBuilderFactory();
    factory.setNamespaceAware(false);
    try {
      return factory.newDocumentBuilder().parse(in);
    } catch(IOException e) {
      throw new RuntimeIOException(e);
    }
  }

  /** Tests a few methods.

View on GitHub (pinned to 1b7edd19c4)