stanfordnlp/CoreNLP · error · RuntimeException

error:\n \ninput:\n \noutput:\n

Error message

error:\n%s\ninput:\n%s\noutput:\n%s

What it means

GUTimeAnnotator runs an external GUTime perl process and parses its stdout as XML. XMLUtils.parseElement failed on that output, so the annotator wraps the parser exception together with the original input text and raw output in a RuntimeException. This means the GUTime binary produced output that is not well-formed XML, or the process failed entirely.

Solutions

  1. Run the GUTime perl script manually on a small input file to reproduce and see the real underlying error in the wrapped exception (`ex`)
  2. Verify perl and GUTime's required modules are installed and the script is executable (check `perl -v` and GUTime docs)
  3. Print the captured `output` from the exception message and fix the input text that breaks it (control characters, invalid encoding)
  4. Sanitize input: strip non-XML-safe characters (control chars, invalid UTF-8) before annotating
  5. Consider switching to SUTime (pure-Java, bundled with CoreNLP) instead of the perl-based GUTime

Example fix

// before
String raw = text; // may contain control chars that break GUTime output XML
pipeline.annotate(raw);
// after
String clean = text.replaceAll("\\p{Cntrl}", "").getBytes("UTF-8") != null ? new String(text.getBytes("UTF-8"), "UTF-8") : text;
Annotation ann = new Annotation(clean);
pipeline.annotate(ann);
Defensive patterns

Strategy: try-catch

Validate before calling

// Java: sanitize input before annotation
String safe = text.replaceAll("\\p{Cntrl}", "");
byte[] bytes = safe.getBytes(java.nio.charset.StandardCharsets.UTF_8);
if (bytes.length == 0) throw new IllegalArgumentException("empty input for GUTime");
// also verify environment once at startup:
Process p = new ProcessBuilder("perl", "-v").start();
if (p.waitFor() != 0) throw new IllegalStateException("perl unavailable for GUTimeAnnotator");

Type guard

boolean isGutimeReady(String text) {
  return text != null && !text.trim().isEmpty()
      && text.equals(new String(text.getBytes(java.nio.charset.StandardCharsets.UTF_8), java.nio.charset.StandardCharsets.UTF_8));
}

Try / catch

try {
  pipeline.annotate(annotation);
} catch (RuntimeException e) {
  if (e.getMessage() != null && e.getMessage().startsWith("error:")) {
    // log e.getCause() and the raw output embedded in the message; fall back to no time annotation
    logger.warning("GUTime failed: " + e.getCause());
  } else throw e;
}

Prevention

When it happens

Trigger: Calling GUTimeAnnotator.annotate on an Annotation when (a) the bundled GUTime perl script/environment is broken (wrong perl version, missing perl modules, wrong gutime path), (b) GUTime crashes mid-processing and emits partial/garbage output, or (c) locale/encoding issues corrupt the XML (e.g. non-UTF8 bytes in the piped output).

Common situations: Deploying to a server without perl or without the modules GUTime needs (Perl4::CoreLibs etc.); macOS/Linux perl version differences; text containing characters that break GUTime's output encoding; running under a security sandbox that blocks the perl subprocess.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/time/GUTimeAnnotator.java:114

    output = docClose.matcher(output).replaceAll("</DOC>");


   //The TimeTag.pl result file contains next tags which must be removed
    output = output.replaceAll("<lex.*?>", "");
    output = output.replace("</lex>", "");
    output = output.replace("<NG>", "");
    output = output.replace("</NG>", "");
    output = output.replace("<VG>", "");
    output = output.replace("</VG>", "");
    output = output.replace("<s>", "");
    output = output.replace("</s>", "");

    // parse the GUTime output
    Element outputXML;
    try {
      outputXML = XMLUtils.parseElement(output);
    } catch (Exception ex) {
      throw new RuntimeException(String.format("error:\n%s\ninput:\n%s\noutput:\n%s",
      		ex, IOUtils.slurpFile(inputFile), output), ex);
    }
    /*
    try {
      outputXML = new SAXBuilder().build(new StringReader(output)).getRootElement();
    } catch (JDOMException e) {
      throw new RuntimeException(String.format("error:\n%s\ninput:\n%s\noutput:\n%s",
      		e, IOUtils.slurpFile(inputFile), output));
    } */
    inputFile.delete();

    


    // get Timex annotations
    List<CoreMap> timexAnns = toTimexCoreMaps(outputXML, document);
    document.set(TimeAnnotations.TimexAnnotations.class, timexAnns);
    if (outputResults) {

View on GitHub (pinned to 1b7edd19c4)