{"record":{"id":"fa65c88a61b0467f","repo":"stanfordnlp/CoreNLP","slug":"unexpected-content-content","errorCode":null,"errorMessage":"unexpected content ${content}","messagePattern":"unexpected content (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/time/GUTimeAnnotator.java","lineNumber":323,"sourceCode":"            searchStep = 1;\n            Integer tokEnd = endMap.get(charEnd);\n            while(tokEnd == null){\n              tokEnd = endMap.get(charEnd - searchStep);\n              if(tokEnd == null){\n                tokEnd = endMap.get(charEnd + searchStep);\n              }\n              searchStep += 1;\n            }\n            timexMap.set(CoreAnnotations.TokenBeginAnnotation.class, tokBegin);\n            timexMap.set(CoreAnnotations.TokenEndAnnotation.class, tokEnd);\n          }\n          //(add)\n          timexMaps.add(timexMap);\n        } else {\n          throw new RuntimeException(\"unexpected element \" + child);\n        }\n      } else {\n        throw new RuntimeException(\"unexpected content \" + content);\n      }\n    }\n    return timexMaps;\n  }\n\n\n  @Override\n  public Set<Class<? extends CoreAnnotation>> requires() {\n    return Collections.unmodifiableSet(new ArraySet<>(Arrays.asList(\n        CoreAnnotations.TextAnnotation.class,\n        CoreAnnotations.TokensAnnotation.class,\n        CoreAnnotations.CharacterOffsetBeginAnnotation.class,\n        CoreAnnotations.CharacterOffsetEndAnnotation.class,\n        CoreAnnotations.SentencesAnnotation.class\n    )));\n  }\n\n  @Override","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/time/GUTimeAnnotator.java#L305-L341","documentation":"In the same iteration over GUTime's XML output, children are expected to be either Text nodes or Elements; any other DOM node type (e.g. Comment, CDATA, ProcessingInstruction nodes) hits this RuntimeException. It signals GUTime produced output content the converter does not model.","triggerScenarios":"GUTime output XML contains comment nodes, CDATA sections, or processing instructions interleaved with the text — often from markup or special characters in the annotated document.","commonSituations":"Annotating text containing embedded comments or unusual characters that GUTime serializes as comments/CDATA; malformed input being echoed into the output XML.","solutions":["Log the offending node (included in the message) to identify its DOM type","Clean the input text: remove control characters and embedded comment/CDATA-like markup before annotation","Preprocess GUTime XML to drop comment/CDATA nodes before toTimexCoreMaps runs","Pin a GUTime version known to emit only text and TIMEX3 elements"],"exampleFix":"// before\nString text = messyInput; // may contain control chars / comment-like markup\nnew GUTimeAnnotator().annotate(new Annotation(text));\n// after\nString text = messyInput.replaceAll(\"\\\\p{Cntrl}|<!--[\\\\s\\\\S]*?-->\", \"\");\nnew GUTimeAnnotator().annotate(new Annotation(text));","handlingStrategy":"validation","validationCode":"// Reject non-text/non-element DOM nodes in GUTime output up front\nNodeList children = outputXML.getDocumentElement().getChildNodes();\nfor (int i = 0; i < children.getLength(); i++) {\n  short type = children.item(i).getNodeType();\n  if (type != org.w3c.dom.Node.TEXT_NODE && type != org.w3c.dom.Node.ELEMENT_NODE)\n    throw new IllegalStateException(\"Non-standard node type \" + type + \" in GUTime output\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  guTimeAnnotator.annotate(annotation);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"unexpected content\")) {\n    logger.warning(\"GUTime emitted non-text/non-element node: \" + e.getMessage());\n  } else throw e;\n}","preventionTips":["Remove control characters and comment-like markup from input before annotation","Sanitize GUTime XML output (drop comments/CDATA) prior to conversion","Test with representative documents from your domain before production use"],"tags":["java","nlp","xml","parsing"],"backgroundTag":"unexpected-response-shape","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"}