{"record":{"id":"6c1fda15878d6617","repo":"stanfordnlp/CoreNLP","slug":"year-not-in-iso-format-y","errorCode":null,"errorMessage":"Year not in ISO format ${y}","messagePattern":"Year not in ISO format (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/time/SUTime.java","lineNumber":3326,"sourceCode":"    public IsoDate(Number y, Number m, Number d, Number era, Boolean yearEraAdjustNeeded) {\n      this.year = (y != null)? y.intValue():-1;\n      this.month = (m != null)? m.intValue():-1;\n      this.day = (d != null)? d.intValue():-1;\n      this.era = (era != null)? era.intValue():ERA_UNKNOWN;\n      if (yearEraAdjustNeeded != null && yearEraAdjustNeeded && this.era == ERA_BC) {\n        if (this.year > 0) {\n          this.year--;\n        }\n      }\n      initBase();\n    }\n\n\n    // Assumes y, m, d are ISO formatted\n    public IsoDate(String y, String m, String d) {\n      if (y != null && !PAD_FIELD_UNKNOWN4.equals(y)) {\n        if (!y.matches(\"[+-]?[0-9X]{4}\")) {\n          throw new IllegalArgumentException(\"Year not in ISO format \" + y);\n        }\n        if (y.startsWith(\"-\")) {\n          y = y.substring(1);\n          era = ERA_BC; // BC\n        } else if (y.startsWith(\"+\")) {\n          y = y.substring(1);\n          era = ERA_AD; // AD\n        }\n        if (y.contains(PAD_FIELD_UNKNOWN)) {\n        } else {\n          year = Integer.parseInt(y);\n        }\n      } else {\n        y = PAD_FIELD_UNKNOWN4;\n      }\n      if (m != null && !PAD_FIELD_UNKNOWN2.equals(m)) {\n        month = Integer.parseInt(m);\n      } else {","sourceCodeStart":3308,"sourceCodeEnd":3344,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/time/SUTime.java#L3308-L3344","documentation":"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'.","triggerScenarios":"Constructing new SUTime.IsoDate(y, m, d) where y is e.g. '85', '198', '1990' (5 chars), 'ab', or contains separators like '1980-'.","commonSituations":"Programmatically building SUTime temporal objects from non-TimeML sources (databases, user input) where years are 2-digit, truncated, or free-form.","solutions":["Normalize the year to exactly 4 digits before constructing IsoDate (e.g. '85' -> '0085' or map to 1985)","Use the SUTime temporal parsing API (Duration/Temporal parse) instead of hand-constructing IsoDate","Validate with y.matches(\"[+-]?[0-9X]{4}\") before the call","Strip leading/trailing whitespace and any non-digit characters"],"exampleFix":"// before\nIsoDate d = new IsoDate(\"85\", \"07\", \"04\");\n// after\nString y = \"85\";\nif (!y.matches(\"[+-]?[0-9X]{4}\")) {\n  y = y.length() == 2 ? (Integer.parseInt(y) < 50 ? \"20\" : \"19\") + y : y;\n}\nIsoDate d = new IsoDate(y, \"07\", \"04\");","handlingStrategy":"validation","validationCode":"if (y == null || !y.matches(\"[+-]?[0-9X]{4}\")) { throw new IllegalArgumentException(\"year must be ISO: \" + y); }","typeGuard":"boolean isIsoYear(String y) { return y != null && y.matches(\"[+-]?[0-9X]{4}\"); }","tryCatchPattern":"try { new SUTime.IsoDate(y, m, d); } catch (IllegalArgumentException e) { /* normalize or reject year */ }","preventionTips":["Normalize years to 4-digit ISO before constructing SUTime temporals","Use SUTime's own parsing APIs rather than hand-building IsoDate","Validate all date components (y/m/d) against ISO patterns first"],"tags":["java","sutime","iso-date"],"backgroundTag":"invalid-date-format","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}