stanfordnlp/CoreNLP · error · IllegalArgumentException

Year not in ISO format

Error message

Year not in ISO format ${y}

What it means

SUTime's IsoDate constructor validates that the year string is ISO-formatted: 4 characters of digits or 'X' (unknown), optionally preceded by '+' or '-'. Anything else throws IllegalArgumentException 'Year not in ISO format'.

Solutions

  1. Normalize the year to exactly 4 digits before constructing IsoDate (e.g. '85' -> '0085' or map to 1985)
  2. Use the SUTime temporal parsing API (Duration/Temporal parse) instead of hand-constructing IsoDate
  3. Validate with y.matches("[+-]?[0-9X]{4}") before the call
  4. Strip leading/trailing whitespace and any non-digit characters

Example fix

// before
IsoDate d = new IsoDate("85", "07", "04");
// after
String y = "85";
if (!y.matches("[+-]?[0-9X]{4}")) {
  y = y.length() == 2 ? (Integer.parseInt(y) < 50 ? "20" : "19") + y : y;
}
IsoDate d = new IsoDate(y, "07", "04");
Defensive patterns

Strategy: validation

Validate before calling

if (y == null || !y.matches("[+-]?[0-9X]{4}")) { throw new IllegalArgumentException("year must be ISO: " + y); }

Type guard

boolean isIsoYear(String y) { return y != null && y.matches("[+-]?[0-9X]{4}"); }

Try / catch

try { new SUTime.IsoDate(y, m, d); } catch (IllegalArgumentException e) { /* normalize or reject year */ }

Prevention

When it happens

Trigger: Constructing new SUTime.IsoDate(y, m, d) where y is e.g. '85', '198', '1990' (5 chars), 'ab', or contains separators like '1980-'.

Common situations: Programmatically building SUTime temporal objects from non-TimeML sources (databases, user input) where years are 2-digit, truncated, or free-form.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/time/SUTime.java:3326

    public IsoDate(Number y, Number m, Number d, Number era, Boolean yearEraAdjustNeeded) {
      this.year = (y != null)? y.intValue():-1;
      this.month = (m != null)? m.intValue():-1;
      this.day = (d != null)? d.intValue():-1;
      this.era = (era != null)? era.intValue():ERA_UNKNOWN;
      if (yearEraAdjustNeeded != null && yearEraAdjustNeeded && this.era == ERA_BC) {
        if (this.year > 0) {
          this.year--;
        }
      }
      initBase();
    }


    // Assumes y, m, d are ISO formatted
    public IsoDate(String y, String m, String d) {
      if (y != null && !PAD_FIELD_UNKNOWN4.equals(y)) {
        if (!y.matches("[+-]?[0-9X]{4}")) {
          throw new IllegalArgumentException("Year not in ISO format " + y);
        }
        if (y.startsWith("-")) {
          y = y.substring(1);
          era = ERA_BC; // BC
        } else if (y.startsWith("+")) {
          y = y.substring(1);
          era = ERA_AD; // AD
        }
        if (y.contains(PAD_FIELD_UNKNOWN)) {
        } else {
          year = Integer.parseInt(y);
        }
      } else {
        y = PAD_FIELD_UNKNOWN4;
      }
      if (m != null && !PAD_FIELD_UNKNOWN2.equals(m)) {
        month = Integer.parseInt(m);
      } else {

View on GitHub (pinned to 1b7edd19c4)