languagetool-org/languagetool · error · RuntimeException

Expected date in format 'yyyy-mm-dd': '" + dateString + "'

Error message

Expected date in format 'yyyy-mm-dd': '" + dateString + "'

What it means

YMDDateHelper.parseDate splits the 'date' value on '-' and requires exactly 3 parts (year, month, day). This RuntimeException is thrown when the date string does not have the yyyy-mm-dd shape (wrong separator, missing fields, or extra dashes).

Source

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

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()
            .replace("{realDate}", correctDate);
    RuleMatch ruleMatch = new RuleMatch(match.getRule(), match.getSentence(), match.getFromPos(),
            match.getToPos(), message, match.getShortMessage());
    ruleMatch.setType(match.getType());

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Format the 'date' value as exactly yyyy-mm-dd, e.g. '2026-12-31'.
  2. Replace alternate separators ('/', '.') with '-'.
  3. If generating the date programmatically, use a formatter with pattern yyyy-MM-dd and zero-padded fields.

Example fix

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

Strategy: validation

Validate before calling

// validate date format before use
String date = args.get("date");
if (date != null && !date.matches("\\d{4}-\\d{2}-\\d{2}"))
    throw new IllegalArgumentException("date must be yyyy-mm-dd: " + date);

Try / catch

try { helper.parseDate(args); } catch (RuntimeException e) { log.error("Invalid date value: " + e.getMessage()); throw e; }

Prevention

When it happens

Trigger: Passing a 'date' argument like '2026/12/31', '20261231', '31.12.2026', or a malformed value with more than two dashes (e.g. '2026-12-31-x').

Common situations: Locale-formatted dates pasted into rule XML; using slashes instead of hyphens; dynamic dates generated in a different format by upstream code.

Related errors


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