languagetool-org/languagetool · error

Could not find month '<monthStr>'

Error message

Could not find month '<monthStr>'

What it means

The Polish DateCheckFilter's getMonth accepts only exact genitive month names (stycznia…grudnia) or Roman numerals (I…XII) and throws this RuntimeException otherwise. Unlike the weekday mapping it uses equals(), not startsWith, so any inflected or abbreviated variant fails.

Source

Thrown at languagetool-language-modules/pl/src/main/java/org/languagetool/rules/pl/DateCheckFilter.java:70

  }

  @SuppressWarnings({"ControlFlowStatementWithoutBraces", "MagicNumber"})
  @Override
  protected int getMonth(String monthStr) {
    String mon = monthStr.toLowerCase();
    if (mon.equals("stycznia") || monthStr.equals("I")) return 1;
    if (mon.equals("lutego") || monthStr.equals("II")) return 2;
    if (mon.equals("marca") || monthStr.equals("III")) return 3;
    if (mon.equals("kwietnia") || monthStr.equals("IV")) return 4;
    if (mon.equals("maja") || monthStr.equals("V")) return 5;
    if (mon.equals("czerwca") || monthStr.equals("VI")) return 6;
    if (mon.equals("lipca") || monthStr.equals("VII")) return 7;
    if (mon.equals("sierpnia") || monthStr.equals("VIII")) return 8;
    if (mon.equals("września") || monthStr.equals("IX")) return 9;
    if (mon.equals("października") || monthStr.equals("X")) return 10;
    if (mon.equals("listopada") || monthStr.equals("XI")) return 11;
    if (mon.equals("grudnia") || monthStr.equals("XII")) return 12;
    throw new RuntimeException("Could not find month '" + monthStr + "'");
  }
}

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Extend getMonth with equals()/startsWith branches for the form shown in the message
  2. Normalize case before comparing (toLowerCase for names, toUpperCase for Roman numerals)
  3. Restrict the rule regex to the exact forms the mapping supports, or map additional inflections

Example fix

// before
if (mon.equals("grudnia") || monthStr.equals("XII")) return 12;
throw new RuntimeException("Could not find month '" + monthStr + "'");
// after
if (mon.equals("grudnia") || monthStr.equalsIgnoreCase("XII")) return 12;
if (mon.equals("grudzień") || mon.equals("gru")) return 12; // accept extra forms as needed
throw new RuntimeException("Could not find month '" + monthStr + "'");
Defensive patterns

Strategy: validation

Validate before calling

Set<String> ok = Set.of("stycznia","lutego","marca","kwietnia","maja","czerwca","lipca","sierpnia","września","października","listopada","grudnia","I","II","III","IV","V","VI","VII","VIII","IX","X","XI","XII");
if (!ok.contains(monthStr)) throw new IllegalArgumentException("Unrecognized Polish month: " + monthStr);

Type guard

boolean isPolishMonth(String s) { return s != null && (Set.of("stycznia","lutego","marca","kwietnia","maja","czerwca","lipca","sierpnia","września","października","listopada","grudnia").contains(s) || s.matches("[IVX]+")); }

Try / catch

try { month = filter.getMonth(monthStr); } catch (RuntimeException e) { log.warn("Polish month unmatched: {}", monthStr); return null; }

Prevention

When it happens

Trigger: A rule matches a month in a case not exactly equal to the expected genitive form (e.g. nominative 'styczeń', 'lipiec') or a Roman numeral outside the listed ones; case mismatch ('Lipca').

Common situations: Dates written with nominative month names or non-standard abbreviations ('sty', 'wrz'); uppercase Roman numerals vs lowercase ('vii').

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/9bdcd9ec2b345db2. Report an issue: GitHub.