stanfordnlp/CoreNLP · error · RuntimeException
unexpected content
Error message
unexpected content ${content} What it means
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.
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
Example fix
// before
String text = messyInput; // may contain control chars / comment-like markup
new GUTimeAnnotator().annotate(new Annotation(text));
// after
String text = messyInput.replaceAll("\\p{Cntrl}|<!--[\\s\\S]*?-->", "");
new GUTimeAnnotator().annotate(new Annotation(text)); Defensive patterns
Strategy: validation
Validate before calling
// Reject non-text/non-element DOM nodes in GUTime output up front
NodeList children = outputXML.getDocumentElement().getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
short type = children.item(i).getNodeType();
if (type != org.w3c.dom.Node.TEXT_NODE && type != org.w3c.dom.Node.ELEMENT_NODE)
throw new IllegalStateException("Non-standard node type " + type + " in GUTime output");
} Try / catch
try {
guTimeAnnotator.annotate(annotation);
} catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().startsWith("unexpected content")) {
logger.warning("GUTime emitted non-text/non-element node: " + e.getMessage());
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Annotating text containing embedded comments or unusual characters that GUTime serializes as comments/CDATA; malformed input being echoed into the output XML.
Related errors
- TIMEX3 should only contain text
- unexpected element
- Bad number put into wordToNumber. Word is: \"" + input +…
- Error in wordToNumber function.
- Bad number put into wordToNumber. Word is: \"" + curPart +…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/fa65c88a61b0467f.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/time/GUTimeAnnotator.java:323
searchStep = 1;
Integer tokEnd = endMap.get(charEnd);
while(tokEnd == null){
tokEnd = endMap.get(charEnd - searchStep);
if(tokEnd == null){
tokEnd = endMap.get(charEnd + searchStep);
}
searchStep += 1;
}
timexMap.set(CoreAnnotations.TokenBeginAnnotation.class, tokBegin);
timexMap.set(CoreAnnotations.TokenEndAnnotation.class, tokEnd);
}
//(add)
timexMaps.add(timexMap);
} else {
throw new RuntimeException("unexpected element " + child);
}
} else {
throw new RuntimeException("unexpected content " + content);
}
}
return timexMaps;
}
@Override
public Set<Class<? extends CoreAnnotation>> requires() {
return Collections.unmodifiableSet(new ArraySet<>(Arrays.asList(
CoreAnnotations.TextAnnotation.class,
CoreAnnotations.TokensAnnotation.class,
CoreAnnotations.CharacterOffsetBeginAnnotation.class,
CoreAnnotations.CharacterOffsetEndAnnotation.class,
CoreAnnotations.SentencesAnnotation.class
)));
}
@OverrideView on GitHub (pinned to 1b7edd19c4)