languagetool-org/languagetool · error · RuntimeException

Set only 'weekDay' and 'date' for " + YMDDateCheckFilter.cla

Error message

Set only 'weekDay' and 'date' for " + YMDDateCheckFilter.class.getSimpleName()

What it means

YMDDateCheckFilter.acceptRuleMatch validates which parameters a regex/date rule may set. This filter only supports the 'weekDay' and 'date' arguments; if the rule XML passes 'year', 'month' or 'day' (which belong to other date filters), it throws a RuntimeException naming the filter class.

Source

Thrown at languagetool-language-modules/en/src/main/java/org/languagetool/rules/en/YMDDateCheckFilter.java:39

import org.languagetool.AnalyzedTokenReadings;
import org.languagetool.rules.RuleMatch;
import org.languagetool.rules.YMDDateHelper;

import java.util.List;
import java.util.Map;

/**
 * Date filter that expects a 'date' argument in the format 'yyyy-mm-dd'.
 * @since 3.2
 */
public class YMDDateCheckFilter extends DateCheckFilter {

  private final YMDDateHelper ymdDateHelper = new YMDDateHelper();

  @Override
  public RuleMatch acceptRuleMatch(RuleMatch match, Map<String, String> args, int patternTokenPos, AnalyzedTokenReadings[] patternTokens, List<Integer> tokenPositions) {
    if (args.containsKey("year") || args.containsKey("month") || args.containsKey("day")) {
      throw new RuntimeException("Set only 'weekDay' and 'date' for " + YMDDateCheckFilter.class.getSimpleName());
    }
    return super.acceptRuleMatch(match, ymdDateHelper.parseDate(args), patternTokenPos, patternTokens, tokenPositions);
  }

}

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Remove year/month/day from the rule's filter args, keeping only weekDay and/or date
  2. If the rule needs year/month/day matching, use the date filter class designed for those arguments
  3. Re-run the rule against a test sentence after editing the XML

Example fix

<!-- before -->
<filter class="org.languagetool.rules.en.YMDDateCheckFilter" args="date:\d year:(\d+) month:(\d+) day:(\d+)"/>
<!-- after -->
<filter class="org.languagetool.rules.en.YMDDateCheckFilter" args="date:\d weekDay:MONDAY|TUESDAY"/>
Defensive patterns

Strategy: validation

Validate before calling

// validate rule XML filter args before loading rules
Set<String> allowed = Set.of("weekDay", "date");
Map<String,String> args = parseFilterArgs(xmlFilterArgs);
args.keySet().retainAll(Set.of("year","month","day","weekDay","date"));
if (args.keySet().stream().anyMatch(k -> !allowed.contains(k))) {
  throw new IllegalStateException("YMDDateCheckFilter accepts only weekDay/date");
}

Try / catch

try {
  rule = language.getRuleById("EN_YMD_DATE", sentence);
  tool.check(sentence);
} catch (RuntimeException e) {
  if (e.getMessage().contains("Set only 'weekDay' and 'date'")) {
    log.error("rule XML uses unsupported filter args: " + e.getMessage());
  } else throw e;
}

Prevention

When it happens

Trigger: A Grammar/regex rule XML uses <filter class="...YMDDateCheckFilter" args="..."/> but includes year=, month= or day= in its filter arguments, e.g. copied from a DMYDateCheckFilter-style rule.

Common situations: Copy-pasting filter args between date-check rule variants; writing a new English date rule and mixing filter argument conventions; renaming/merging date rules without updating args.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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