{"record":{"id":"2bccb69d450987a0","repo":"stanfordnlp/CoreNLP","slug":"error-n-s-ninput-n-s","errorCode":null,"errorMessage":"error:\\n%s\\ninput:\\n%s","messagePattern":"error:\\\\n(.+?)\\\\ninput:\\\\n(.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/time/ParsedGigawordReader.java","lineNumber":188,"sourceCode":"    matcher.find();\n    Calendar docDate = new Timex(matcher.group(1)).getDate();\n\n    Annotation document = new Annotation(text.toString());\n    document.set(CoreAnnotations.DocIDAnnotation.class, docID);\n    document.set(CoreAnnotations.CalendarAnnotation.class, docDate);\n    document.set(CoreAnnotations.SentencesAnnotation.class, sentences);\n    return document;\n  }\n  */\n\n  private static Annotation toAnnotation(String xml) throws IOException {\n    Element docElem;\n    try {\n      Builder parser = new Builder();\n      StringReader in = new StringReader(xml);\n      docElem = parser.build(in).getRootElement();\n    } catch (ParsingException | IOException e) {\n      throw new RuntimeException(String.format(\"error:\\n%s\\ninput:\\n%s\", e, xml));\n    }\n\n    Element textElem = docElem.getFirstChildElement(\"TEXT\");\n    StringBuilder text = new StringBuilder();\n    int offset = 0;\n    List<CoreMap> sentences = new ArrayList<>();\n    Elements sentenceElements = textElem.getChildElements(\"SENT\");\n    for (int crtsent = 0; crtsent < sentenceElements.size(); crtsent ++){\n      Element sentElem = sentenceElements.get(crtsent);\n      CoreMap sentence = new ArrayCoreMap();\n      sentence.set(CoreAnnotations.CharacterOffsetBeginAnnotation.class, offset);\n      Tree tree = Tree.valueOf(sentElem.getChild(0).getValue()); // XXX ms: is this the same as sentElem.getText() in JDOM?\n      List<CoreLabel> tokens = new ArrayList<>();\n      List<Tree> preTerminals = preTerminals(tree);\n      for (Tree preTerminal: preTerminals) {\n        String posTag = preTerminal.value();\n        for (Tree wordTree: preTerminal.children()) {\n          String word = wordTree.value();","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/time/ParsedGigawordReader.java#L170-L206","documentation":"toAnnotation parses the assembled gigaword XML with XOM's Builder. If the XML is malformed (ParsingException) or reading fails (IOException), the method throws a RuntimeException containing the parser error and the full offending XML input, so the developer can see exactly what failed to parse.","triggerScenarios":"The regex rewrites (adding quotes around sid, inserting </TEXT>) producing invalid XML — unescaped '&', '<' in the text, attributes not properly quoted, or nested markup that violates XML well-formedness.","commonSituations":"Gigaword sentences containing raw '&' or '<' characters that were never XML-escaped; sid attributes with characters breaking the naive sid regex fix; documents missing expected SENT/TEXT structure.","solutions":["Read the parser error in the exception message to find the malformed position, then fix the source document or pre-escape entities.","Escape XML special characters (&, <, >) in the text content before building the string (e.g. with StringEscapeUtils.escapeXml10).","Fix the pre-processing regexes (sid quoting, </TEXT> insertion) so they generate well-formed XML for edge-case documents."],"exampleFix":"// before\nxml = new String(xml.getBytes(), \"UTF8\");\nreturn toAnnotation(xml);\n// after\nxml = xml.replaceAll(\"&(?!(amp|lt|gt|quot|apos|#\\\\d+|#x[0-9a-fA-F]+);)\", \"&amp;\");\nxml = new String(xml.getBytes(), \"UTF8\");\nreturn toAnnotation(xml);","handlingStrategy":"try-catch","validationCode":"// sanity-check XML well-formedness before toAnnotation\nif (!xml.startsWith(\"<DOC\") || xml.contains(\"<&\") || countUnescapedAmpersands(xml) > 0) {\n  logger.warning(\"Suspicious XML for document: \" + xml.substring(0, 200));\n}","typeGuard":null,"tryCatchPattern":"try {\n  CoreMap doc = ParsedGigawordReader.toAnnotation(xml);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"error:\")) {\n    logger.warning(\"Unparseable XML, skipping: \" + e.getMessage().substring(0, 300));\n    return null; // skip document\n  }\n  throw e;\n}","preventionTips":["XML-escape &, <, > in gigaword text content before assembling documents","Test the sid/TEXT rewriting regexes against edge-case documents","Keep the parser error message (input included) for diagnosis"],"tags":["xml","parsing","gigaword","escaping"],"backgroundTag":"invalid-json-response","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"}