{"record":{"id":"08ac65e7d706b07e","repo":"languagetool-org/languagetool","slug":"missing-key-date","errorCode":null,"errorMessage":"Missing key 'date'","messagePattern":"Missing key 'date'","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"languagetool-core/src/main/java/org/languagetool/rules/YMDDateHelper.java","lineNumber":34,"sourceCode":" * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301\n * USA\n */\npackage org.languagetool.rules;\n\nimport java.util.Map;\n\n/**\n * @since 4.3\n */\npublic class YMDDateHelper {\n\n  public YMDDateHelper() {\n  }\n\n  public Map<String, String> parseDate(Map<String, String> args) {\n    String dateString = args.get(\"date\");\n    if (dateString == null) {\n      throw new IllegalArgumentException(\"Missing key 'date'\");\n    }\n    String[] parts = dateString.split(\"-\");\n    if (parts.length != 3) {\n      throw new RuntimeException(\"Expected date in format 'yyyy-mm-dd': '\" + dateString + \"'\");\n    }\n    args.put(\"year\", parts[0]);\n    args.put(\"month\", parts[1]);\n    args.put(\"day\", parts[2]);\n    return args;\n  }\n\n  public RuleMatch correctDate(RuleMatch match, Map<String, String> args) {\n    String year = args.get(\"year\");\n    String month = args.get(\"month\");\n    String day = args.get(\"day\");\n    int correctYear = Integer.parseInt(year) + 1;\n    String correctDate = String.format(\"%d-%s-%s\", correctYear, month, day);\n    String message = match.getMessage()","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-core/src/main/java/org/languagetool/rules/YMDDateHelper.java#L16-L52","documentation":"Generic validation guard in the date-parsing helper: the args map handed to parseDate does not contain the required 'date' entry, so nothing can be split into year/month/day. The input at fault is the caller-supplied argument map (typically the arguments of a <filter> in an XML rule) that omitted the 'date' key.","triggerScenarios":"A rule XML uses a date-evaluated filter (YMDDateHelper) but omits the required 'date' argument from the token/filter arguments.","commonSituations":"Custom grammar rules missing the date attribute; renaming the attribute (e.g. to 'expiry') without updating parseDate expectations; copying rule templates and dropping attributes.","solutions":["Add a 'date' argument in yyyy-mm-dd format to the rule/filter definition, e.g. date=\"2026-12-31\".","Check spelling/casing of the attribute — it must be exactly 'date'.","If the date comes from a placeholder, ensure the placeholder is populated before the filter runs."],"exampleFix":"// before (rule XML)\n<filter class=\"...YMDDateHelper\"/>\n// after (rule XML)\n<filter class=\"...YMDDateHelper\" date=\"2026-12-31\"/>","handlingStrategy":"validation","validationCode":"// check required key before invoking the filter\nif (!args.containsKey(\"date\"))\n    throw new IllegalArgumentException(\"Rule XML must define a 'date' attribute for YMDDateHelper\");","typeGuard":null,"tryCatchPattern":"try { helper.parseDate(args); } catch (IllegalArgumentException e) { log.error(\"Rule configuration error: \" + e.getMessage()); throw e; }","preventionTips":["Always include date=\"yyyy-mm-dd\" in rules using YMDDateHelper","Copy attribute sets from working example rules","Validate rule XML against the schema before deployment"],"tags":["java","rule-xml","argument-validation","languagetool"],"backgroundTag":"missing-required-argument","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}