languagetool-org/languagetool · error · IllegalArgumentException

Missing key 'date'

Error message

Missing key 'date'

What it means

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.

Source

Thrown at languagetool-core/src/main/java/org/languagetool/rules/YMDDateHelper.java:34

 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
 * USA
 */
package org.languagetool.rules;

import java.util.Map;

/**
 * @since 4.3
 */
public class YMDDateHelper {

  public YMDDateHelper() {
  }

  public Map<String, String> parseDate(Map<String, String> args) {
    String dateString = args.get("date");
    if (dateString == null) {
      throw new IllegalArgumentException("Missing key 'date'");
    }
    String[] parts = dateString.split("-");
    if (parts.length != 3) {
      throw new RuntimeException("Expected date in format 'yyyy-mm-dd': '" + dateString + "'");
    }
    args.put("year", parts[0]);
    args.put("month", parts[1]);
    args.put("day", parts[2]);
    return args;
  }

  public RuleMatch correctDate(RuleMatch match, Map<String, String> args) {
    String year = args.get("year");
    String month = args.get("month");
    String day = args.get("day");
    int correctYear = Integer.parseInt(year) + 1;
    String correctDate = String.format("%d-%s-%s", correctYear, month, day);
    String message = match.getMessage()

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Add a 'date' argument in yyyy-mm-dd format to the rule/filter definition, e.g. date="2026-12-31".
  2. Check spelling/casing of the attribute — it must be exactly 'date'.
  3. If the date comes from a placeholder, ensure the placeholder is populated before the filter runs.

Example fix

// before (rule XML)
<filter class="...YMDDateHelper"/>
// after (rule XML)
<filter class="...YMDDateHelper" date="2026-12-31"/>
Defensive patterns

Strategy: validation

Validate before calling

// check required key before invoking the filter
if (!args.containsKey("date"))
    throw new IllegalArgumentException("Rule XML must define a 'date' attribute for YMDDateHelper");

Try / catch

try { helper.parseDate(args); } catch (IllegalArgumentException e) { log.error("Rule configuration error: " + e.getMessage()); throw e; }

Prevention

When it happens

Trigger: A rule XML uses a date-evaluated filter (YMDDateHelper) but omits the required 'date' argument from the token/filter arguments.

Common situations: Custom grammar rules missing the date attribute; renaming the attribute (e.g. to 'expiry') without updating parseDate expectations; copying rule templates and dropping attributes.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06). Data as JSON: /api/errors/08ac65e7d706b07e. Report an issue: GitHub.