{"record":{"id":"d4fb96444ac32859","repo":"stanfordnlp/CoreNLP","slug":"fatal-error","errorCode":null,"errorMessage":"Fatal Error","messagePattern":"Fatal Error","errorType":"exception","errorClass":"SAXParseException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/XMLUtils.java","lineNumber":1274,"sourceCode":"        sb.append(\" in entity from publicID \").append(ex.getPublicId());\n      }\n      sb.append('.');\n      return sb.toString();\n    }\n\n    @Override\n    public void warning(SAXParseException exception) {\n      log.warn(makeBetterErrorString(\"Warning\", exception));\n    }\n\n    @Override\n    public void error(SAXParseException exception) {\n      log.error(makeBetterErrorString(\"Error\", exception));\n    }\n\n    @Override\n    public void fatalError(SAXParseException ex) throws SAXParseException {\n      throw new SAXParseException(makeBetterErrorString(\"Fatal Error\", ex),\n              ex.getPublicId(), ex.getSystemId(), ex.getLineNumber(), ex.getColumnNumber());\n      // throw new RuntimeException(makeBetterErrorString(\"Fatal Error\", ex));\n    }\n\n  } // end class SAXErrorHandler\n\n  public static Document readDocumentFromString(String s) throws ParserConfigurationException, SAXException {\n    InputSource in = new InputSource(new StringReader(s));\n    DocumentBuilderFactory factory = safeDocumentBuilderFactory();\n    factory.setNamespaceAware(false);\n    try {\n      return factory.newDocumentBuilder().parse(in);\n    } catch(IOException e) {\n      throw new RuntimeIOException(e);\n    }\n  }\n\n  /** Tests a few methods.","sourceCodeStart":1256,"sourceCodeEnd":1292,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/XMLUtils.java#L1256-L1292","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Open the XML at the reported line/column and fix the well-formedness violation","Re-download or regenerate the XML resource and verify its checksum","Validate the file with xmllint or an XML-aware editor before loading","If the input is HTML or tag-soup, run it through a tolerant parser (e.g. Jsoup) instead of a strict SAX parser"],"exampleFix":"// before\nDocument d = XMLUtils.readDocumentFromFile(\"model.xml\");\n// after\nFile f = new File(\"model.xml\");\nif (!f.exists() || f.length() == 0) throw new IOException(\"model.xml missing/empty\");\nProcess p = new ProcessBuilder(\"xmllint\", \"--noout\", f.getPath()).start();\nif (p.waitFor() != 0) throw new IOException(\"model.xml is not well-formed\");\nDocument d = XMLUtils.readDocumentFromFile(f.getPath());","handlingStrategy":"try-catch","validationCode":"// Pre-validate XML well-formedness\ntry {\n  javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File(\"model.xml\"));\n} catch (org.xml.sax.SAXParseException e) {\n  throw new IOException(\"model.xml malformed at \" + e.getLineNumber() + \":\" + e.getColumnNumber(), e);\n}","typeGuard":null,"tryCatchPattern":"try {\n  Document d = XMLUtils.readDocumentFromFile(\"model.xml\");\n} catch (SAXParseException e) {\n  log.error(\"XML fatal error: {} at line {} col {}\", e.getMessage(), e.getLineNumber(), e.getColumnNumber());\n  // repair or re-fetch the resource before retrying\n}","preventionTips":["Validate XML resources with xmllint in CI before shipping them","Verify checksums of downloaded model/config files to catch truncation","Never feed HTML or log output into a strict XML parser","Always specify and check the file encoding"],"tags":["xml","parsing","sax","fatal-error"],"backgroundTag":"xml-parse-error","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}