{"record":{"id":"ca9ce55850daef6b","repo":"stanfordnlp/CoreNLP","slug":"unexpected-content-content-ca9ce5","errorCode":null,"errorMessage":"unexpected content ${content}","messagePattern":"unexpected content (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/time/HeidelTimeAnnotator.java","lineNumber":257,"sourceCode":"            }\n            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          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  @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\n  public Set<Class<? extends CoreAnnotation>> requirementsSatisfied() {","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/time/HeidelTimeAnnotator.java#L239-L275","documentation":"During parsing of HeidelTime's XML output, toTimexCoreMaps expects every child node to be either a DOM Text node or an Element. Any other DOM node type (comment, CDATA, entity reference, processing instruction, etc.) triggers this RuntimeException because the offset bookkeeping cannot account for it.","triggerScenarios":"The DOM document produced from HeidelTime's stdout contains non-text, non-element nodes — e.g. XML comments or processing instructions inserted by the external heideltime.jar — when iterating docElem.getChildNodes().","commonSituations":"A heideltime.jar variant that emits XML comments in its output; malformed output whose parsing produces unexpected node types; XML headers/PIs surviving into the parsed tree.","solutions":["Inspect the raw HeidelTime output to find what non-text/non-element node appears and adjust the heideltime.jar/config to stop emitting it","Sanitize the XML (strip comments/PIs) before DOM parsing, or parse with a DocumentBuilderFactory configured appropriately","Patch toTimexCoreMaps to skip unsupported node types with a warning instead of throwing"],"exampleFix":"// before\n} else {\n  throw new RuntimeException(\"unexpected content \" + content);\n}\n// after\n} else {\n  // skip comments, CDATA, etc. without altering the offset bookkeeping\n  if (!(content instanceof Text) && !(content instanceof Element)) continue;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"static boolean isTextOrElement(Node n) {\n    return n instanceof Text || n instanceof Element;\n}","tryCatchPattern":"try {\n    pipeline.annotate(annotation);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"unexpected content\")) {\n        logger.warn(\"HeidelTime output contained non-text/element node; skipping doc\");\n    } else {\n        throw e;\n    }\n}","preventionTips":["Use a supported heideltime.jar that emits clean XML without comments/PIs","Sanitize HeidelTime stdout before DOM parsing","Keep the external tool's config.props unmodified","Catch RuntimeException per document in batch pipelines"],"tags":["java","nlp","xml-parsing","runtime-exception"],"backgroundTag":"unexpected-api-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"}