languagetool-org/languagetool · error · RuntimeException

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

Error message

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

What it means

DMYDateCheckFilter parses a French 'dd-mm-yyyy' date and then delegates to DateCheckFilter by filling in day/month/year args. This RuntimeException is thrown when a XML rule supplies 'year', 'month' or 'day' arguments, which this filter does not support; it only accepts 'weekDay' and 'date'. It exists to fail fast on misconfigured grammar rules instead of silently ignoring conflicting args.

Source

Thrown at languagetool-language-modules/fr/src/main/java/org/languagetool/rules/fr/DMYDateCheckFilter.java:36

 */
package org.languagetool.rules.fr;

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

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

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

  @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 " + DMYDateCheckFilter.class.getSimpleName());
    }
    String dateString = getRequired("date", args);
    String[] parts = dateString.split("-");
    if (parts.length != 3) {
      throw new RuntimeException("Expected date in format 'dd-mm-yyyy': '" + dateString + "'");
    }
    args.put("day", parts[0]);
    args.put("month", parts[1]);
    args.put("year", parts[2]);
    return super.acceptRuleMatch(match, args, patternTokenPos, patternTokens, tokenPositions);
  }

}

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Remove the 'year', 'month' and 'day' attributes from the <filter> element in the rule XML.
  2. Express the date as a single 'date' attribute in dd-mm-yyyy form, optionally with 'weekDay'.
  3. If you truly need explicit year/month/day values, use the parent DateCheckFilter class instead of DMYDateCheckFilter.

Example fix

<!-- before -->
<filter class="org.languagetool.rules.fr.DMYDateCheckFilter" args="date:25-12-2024 year:2024"/>
<!-- after -->
<filter class="org.languagetool.rules.fr.DMYDateCheckFilter" args="date:25-12-2024"/>
Defensive patterns

Strategy: validation

Validate before calling

// before evaluating a rule with this filter
Set<String> forbidden = Set.of("year", "month", "day");
if (args.keySet().stream().anyMatch(forbidden::contains)) {
    throw new IllegalArgumentException("DMYDateCheckFilter accepts only 'weekDay' and 'date'");
}

Try / catch

try { filter.acceptRuleMatch(match, args, pos, tokens, tokenPositions); } catch (RuntimeException e) { LOG.error("Bad date-filter config: " + e.getMessage(), e); }

Prevention

When it happens

Trigger: acceptRuleMatch is invoked during rule evaluation of a pattern rule whose <filter class="...DMYDateCheckFilter"> element declares args 'year', 'month' and/or 'day'. Any one of those keys in the args map triggers the throw immediately, before any date parsing.

Common situations: Authors copy an argument set from DMYDateCheckFilter's parent DateCheckFilter (which does accept year/month/day) into a French rule; rule XML refactors leave stale 'day'/'month'/'year' attributes; mixing up the two filters when converting an existing date rule.

Related errors


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