{"record":{"id":"c869d44eb3e8b184","repo":"stanfordnlp/CoreNLP","slug":"xml-failure-while-reading-file","errorCode":null,"errorMessage":"XML failure while reading \" + file","messagePattern":"XML failure while reading \" \\+ file","errorType":"exception","errorClass":"SsurgeonParseException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/Ssurgeon.java","lineNumber":815,"sourceCode":"      throw new SsurgeonParseException(\"XML failure while reading string\", e);\n    }\n  }\n\n  /**\n   * Given a path to a file containing a list of SsurgeonPatterns, returns\n   *\n   * TODO: deal with resources\n   */\n  public List<SsurgeonPattern> readFromFile(File file) {\n    try {\n      Document doc = XMLUtils.readDocumentFromFile(file.getPath());\n\n      if (VERBOSE)\n        System.out.println(\"Reading ssurgeon file=\"+file.getAbsolutePath());\n\n      return readFromDocument(doc);\n    } catch (ParserConfigurationException | SAXException e) {\n      throw new SsurgeonParseException(\"XML failure while reading \" + file, e);\n    }\n  }\n\n  public List<SsurgeonPattern> readFromDocument(Document doc) {\n    List<SsurgeonPattern> retList = new ArrayList<>();\n\n    NodeList patternNodes = doc.getElementsByTagName(SsurgeonPattern.SSURGEON_ELEM_TAG);\n    for (int i=0; i<patternNodes.getLength(); i++) {\n      Node node = patternNodes.item(i);\n      if (node.getNodeType() == Node.ELEMENT_NODE) {\n        Element elt = (Element) node;\n        SsurgeonPattern pattern = ssurgeonPatternFromXML(elt);\n        retList.add(pattern);\n      }\n    }\n\n    NodeList resourceNodes = doc.getElementsByTagName(SsurgeonPattern.RESOURCE_TAG);\n    for (int i=0; i < resourceNodes.getLength(); i++) {","sourceCodeStart":797,"sourceCodeEnd":833,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/Ssurgeon.java#L797-L833","documentation":"readFromFile (the surrounding method) loads an ssurgeon XML file from disk and parses it; ParserConfigurationException or SAXException from reading/parsing the file is wrapped in SsurgeonParseException naming the file path. Unlike readFromString, IOException may propagate separately, so this specifically signals XML parsing problems.","triggerScenarios":"Ssurgeon.readFromFile(file) on a file containing invalid XML: truncated file, wrong root element encoding issues, or binary content with an .xml extension.","commonSituations":"Pointing Ssurgeon at a text/plain ssurgeon rules file instead of XML, or a partially-written/corrupted XML resource.","solutions":["Verify the file is well-formed XML (open in an XML validator or xmllint)","Confirm the correct file path and format — ssurgeon files must be XML","Read the chained cause for the parser's line/column error"],"exampleFix":"# before: passing a plain-text rules file\nssurgeon.readFromFile(new File(\"rules.txt\"));\n# after\nssurgeon.readFromFile(new File(\"rules.xml\")); // valid ssurgeon XML","handlingStrategy":"try-catch","validationCode":"// pre-check: file exists and parses as XML\nboolean isParseableXml(java.io.File f) throws java.io.IOException {\n  try {\n    javax.xml.parsers.DocumentBuilderFactory.newInstance()\n      .newDocumentBuilder().parse(f);\n    return true;\n  } catch (org.xml.sax.SAXException e) { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n  List<SsurgeonPattern> pats = ssurgeon.readFromFile(file);\n} catch (SsurgeonParseException e) {\n  log.severe(\"XML failure in \" + file + \": \" + e.getCause());\n}","preventionTips":["Run xmllint --noout on ssurgeon XML files as a build step","Ensure the path points to XML ssurgeon files, not plain-text rule files","Check file integrity when resources come from packaging/compression"],"tags":["java","xml","ssurgeon","file-parse"],"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-15T23:17:13.987Z"}