{"record":{"id":"d2637b7a30776c3e","repo":"stanfordnlp/CoreNLP","slug":"unexpected-element-child-d2637b","errorCode":null,"errorMessage":"unexpected element ${child}","messagePattern":"unexpected element (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/time/HeidelTimeAnnotator.java","lineNumber":254,"sourceCode":"                tokBegin = beginMap.get(charBegin + searchStep);\n              }\n              searchStep += 1;\n            }\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  }","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/time/HeidelTimeAnnotator.java#L236-L272","documentation":"toTimexCoreMaps walks the children of HeidelTime's XML output document and only knows how to handle Text nodes and TIMEX3 elements. Any other XML element in the output triggers this RuntimeException, since the annotator cannot compute character/token offsets for unknown element types.","triggerScenarios":"The parsed HeidelTime output contains an element other than TIMEX3 (e.g. a different tag emitted by a different/newer heideltime.jar, or DOCTYPE/processing-instruction wrapped as Element-like nodes) while iterating the document element's children.","commonSituations":"Pointing the annotator at a heideltime.jar build whose output tags differ (e.g. TIMEX2 or custom tags); corrupted or hand-edited HeidelTime output; feeding the annotator XML that was not produced by HeidelTime.","solutions":["Confirm the heideltime.jar and config.props under heideltime.path are the supported versions that emit only TIMEX3 tags","Log/print the HeidelTime stdout right before parsing to see the unexpected element and its origin","Ensure the document text passed to the annotator is plain text, not XML containing other tags","Patch toTimexCoreMaps to skip or recursively handle non-TIMEX3 elements instead of throwing"],"exampleFix":"// before\n} else {\n  throw new RuntimeException(\"unexpected element \" + child);\n}\n// after\n} else {\n  System.err.println(\"skipping unexpected element in HeidelTime output: \" + child.getNodeName());\n}","handlingStrategy":"validation","validationCode":"// Pre-check heideltime installation emits only TIMEX3 elements\nString out = runHeidelTimeSample(\"Obama visited Paris on May 1, 2011.\");\nfor (String tag : extractTagNames(out)) {\n    if (!tag.equals(\"TIMEX3\")) throw new IllegalStateException(\"unexpected HeidelTime tag: \" + tag);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin the heideltime.jar version; do not mix CoreNLP and HeidelTime versions","Feed plain text, never pre-annotated XML, into the annotator","Smoke-test the HeidelTime binary on a sample doc after upgrading","Log HeidelTime's raw output on failure for diagnosis"],"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"}