languagetool-org/languagetool · error · RuntimeException

Could not find month '" + monthStr + "'

Error message

Could not find month '" + monthStr + "'

What it means

DateFilterHelper.getMonth(String) maps Spanish month names/abbreviations to numbers 1-12 via prefix matching (enero, feb, mar, abr, may, jun, jul, ag..., se..., oc..., no..., di...). If the string starts with none of the known prefixes it throws RuntimeException.

Source

Thrown at languagetool-language-modules/es/src/main/java/org/languagetool/rules/es/DateFilterHelper.java:74

    return "";
  }

  @SuppressWarnings({"ControlFlowStatementWithoutBraces", "MagicNumber"})
  protected int getMonth(String monthStr) {
    String mon = monthStr.toLowerCase();
    if (mon.startsWith("en")) return 1;
    if (mon.startsWith("fe")) return 2;
    if (mon.startsWith("mar") || mon.startsWith("mzo")) return 3;
    if (mon.startsWith("ab")) return 4;
    if (mon.startsWith("may") || mon.startsWith("my")) return 5;
    if (mon.startsWith("jun") || mon.equals("jn")) return 6;
    if (mon.startsWith("jul") || mon.equals("jl")) return 7;
    if (mon.startsWith("ag")) return 8;
    if (mon.startsWith("se") || mon.startsWith("sep")) return 9;
    if (mon.startsWith("oc")) return 10;
    if (mon.startsWith("no")) return 11;
    if (mon.startsWith("di")) return 12;
    throw new RuntimeException("Could not find month '" + monthStr + "'");
  }
}

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Check the message's month string and either fix the rule regex so it captures a valid Spanish month, or add the spelling as a recognized prefix.
  2. Normalize case/accents in the caller before invoking getMonth.
  3. Ensure optional month tokens are only passed to the filter when actually matched.

Example fix

// before
if (mon.startsWith("se") || mon.startsWith("sep")) return 9;
// after (adds regional spelling)
if (mon.startsWith("se") || mon.startsWith("set")) return 9; // covers setiembre
Defensive patterns

Strategy: validation

Validate before calling

String[] prefixes = {"ene","feb","mar","abr","may","jun","jul","ag","se","oc","no","di"};
String mon = monthStr.toLowerCase();
if (Arrays.stream(prefixes).noneMatch(mon::startsWith)) throw new IllegalArgumentException("Unsupported month: " + monthStr);

Try / catch

try {
  int month = helper.getMonth(monthStr);
} catch (RuntimeException e) {
  LOG.warn("Unrecognized month token '{}' — skipping date check", monthStr);
}

Prevention

When it happens

Trigger: A Spanish date rule passes a month token like 'setiembre', 'deptiembre' (unusual spellings), an empty string, or a non-month token captured by the rule regex to getMonth(monthStr).

Common situations: Regional spellings ('setiembre' in some Latin American usage) that don't start with 'se'... actually 'se' matches setiembre — more often: typos, missing accents handled, or a regex capturing the wrong group; empty capture when the rule's month token is optional.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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