stanfordnlp/CoreNLP · error · RuntimeException

unexpected content

Error message

unexpected content ${content}

What it means

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.

Solutions

  1. Inspect the raw HeidelTime output to find what non-text/non-element node appears and adjust the heideltime.jar/config to stop emitting it
  2. Sanitize the XML (strip comments/PIs) before DOM parsing, or parse with a DocumentBuilderFactory configured appropriately
  3. Patch toTimexCoreMaps to skip unsupported node types with a warning instead of throwing

Example fix

// before
} else {
  throw new RuntimeException("unexpected content " + content);
}
// after
} else {
  // skip comments, CDATA, etc. without altering the offset bookkeeping
  if (!(content instanceof Text) && !(content instanceof Element)) continue;
}
Defensive patterns

Strategy: try-catch

Type guard

static boolean isTextOrElement(Node n) {
    return n instanceof Text || n instanceof Element;
}

Try / catch

try {
    pipeline.annotate(annotation);
} catch (RuntimeException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("unexpected content")) {
        logger.warn("HeidelTime output contained non-text/element node; skipping doc");
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: 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().

Common situations: 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.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/ca9ce55850daef6b. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/time/HeidelTimeAnnotator.java:257

            }
            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);
          }
          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
  public Set<Class<? extends CoreAnnotation>> requirementsSatisfied() {

View on GitHub (pinned to 1b7edd19c4)