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

  1. Log the offending node (included in the message) to identify its DOM type
  2. Clean the input text: remove control characters and embedded comment/CDATA-like markup before annotation
  3. Preprocess GUTime XML to drop comment/CDATA nodes before toTimexCoreMaps runs
  4. 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

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


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
    )));
  }

  @Override

View on GitHub (pinned to 1b7edd19c4)