stanfordnlp/CoreNLP · error · RuntimeException

Error creating DateTimeFormatter

Error message

Error creating DateTimeFormatter

What it means

Thrown while building an extractor rule whose formatter is "org.joda.time.format.ISODateTimeFormat": reflection failed to find or invoke a no-arg static method named by the formatter expr on ISODateTimeFormat, or the returned object was not a DateTimeFormatter. Indicates the rule file names a non-existent ISO formatter.

Solutions

  1. Check the expr in the rule: it must exactly match a public static no-arg method on org.joda.time.format.ISODateTimeFormat (e.g. dateParser, dateTimeParser, date, dateTime).
  2. Verify the Joda-Time version on the classpath supports the named method.
  3. If the pattern is not ISO, switch the rule to formatter=java.text.SimpleDateFormat with a pattern expr.

Example fix

// rule file before
{ formatter: "org.joda.time.format.ISODateTimeFormat", expr: "dateFormat" }
// rule file after
{ formatter: "org.joda.time.format.ISODateTimeFormat", expr: "dateParser" }
Defensive patterns

Strategy: validation

Validate before calling

Set<String> valid = java.util.Arrays.stream(ISODateTimeFormat.class.getMethods())
    .filter(m -> m.getParameterCount() == 0 && DateTimeFormatter.class.isAssignableFrom(m.getReturnType()))
    .map(java.lang.reflect.Method::getName).collect(java.util.stream.Collectors.toSet());
// assert valid.contains(expr) before loading the rule

Try / catch

try {
  loadRules("defs.sutime.txt");
} catch (RuntimeException e) {
  if (e.getMessage() != null && e.getMessage().contains("Error creating DateTimeFormatter")) {
    throw new IllegalStateException("Bad ISO formatter expr in rules file: " + e.getCause(), e);
  } else throw e;
}

Prevention

When it happens

Trigger: In a SUTime rules file (e.g. defs.sutime.txt), specifying formatter=org.joda.time.format.ISODateTimeFormat with expr set to a method name that does not exist on ISODateTimeFormat (typo, wrong casing, or a method from a different Joda class).

Common situations: Hand-editing .sutime.txt rule files, upgrading Joda-Time to a version where a formatter method was removed/renamed, or copying an expr that works for SimpleDateFormat into the ISO branch.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/time/TimeFormatter.java:165

      String localeString = Expressions.asObject(env, attributes.get("locale"));
      r.pattern = expr;
      if (formatter == null) {
        if (r.annotationField == null) { r.annotationField = EnvLookup.getDefaultTextAnnotationKey(env);  }
        /* Parse pattern and figure out what the result should be.... */
        CustomDateFormatExtractor formatExtractor = new CustomDateFormatExtractor(expr, localeString);
        //SequenceMatchRules.Expression result = (SequenceMatchRules.Expression) attributes.get("result");
        updateExtractRule(r, env, formatExtractor.getTextPattern(), new ApplyActionWrapper<>(env, formatExtractor, action));
      } else if ("org.joda.time.format.DateTimeFormat".equals(formatter)) {
        if (r.annotationField == null) { r.annotationField = r.tokensAnnotationField;  }
        updateExtractRule(r, env, new ApplyActionWrapper<>(env, new JodaDateTimeFormatExtractor(expr), action));
      } else if ("org.joda.time.format.ISODateTimeFormat".equals(formatter)) {
        if (r.annotationField == null) { r.annotationField = r.tokensAnnotationField;  }
        try {
          Method m = ISODateTimeFormat.class.getMethod(expr);
          DateTimeFormatter dtf = (DateTimeFormatter) m.invoke(null);
          updateExtractRule(r, env, new ApplyActionWrapper<>(env, new JodaDateTimeFormatExtractor(expr), action));
        } catch (Exception ex) {
          throw new RuntimeException("Error creating DateTimeFormatter", ex);
        }
      } else if ("java.text.SimpleDateFormat".equals(formatter)) {
        if (r.annotationField == null) { r.annotationField = r.tokensAnnotationField;  }
        updateExtractRule(r, env, new ApplyActionWrapper<>(env, new JavaDateFormatExtractor(expr), action));
      } else {
        throw new IllegalArgumentException("Unsupported formatter: " + formatter);
      }
      return r;
    }
  }

  /*
   * Rules for parsing time specific patterns.
   * Patterns are similar to time patterns used by JodaTime combined with a simplified regex expression
   *
   # y       year                         year          1996                         y
   # M       month of year                month         July; Jul; 07                M
   # d       day of month                 number        10                           d

View on GitHub (pinned to 1b7edd19c4)