languagetool-org/languagetool · error
Could not find month '<monthStr>'
Error message
Could not find month '<monthStr>'
What it means
The Italian DateCheckFilter maps Italian month names/abbreviations to month numbers in getMonth. It throws this RuntimeException when the input string matches none of the known prefixes (gen, feb, mar, apr, mag, giu, lug, ago, set, ott, nov, dic). It signals that the month token produced by the calling rule is not in the filter's recognized vocabulary.
Source
Thrown at languagetool-language-modules/it/src/main/java/org/languagetool/rules/it/DateCheckFilter.java:81
}
@SuppressWarnings({"ControlFlowStatementWithoutBraces", "MagicNumber"})
@Override
protected int getMonth(String monthStr) {
String mon = monthStr.toLowerCase();
if (mon.startsWith("gen")) return 1;
if (mon.startsWith("feb")) return 2;
if (mon.startsWith("mar")) return 3;
if (mon.startsWith("apr")) return 4;
if (mon.startsWith("mag")) return 5;
if (mon.startsWith("giu")) return 6;
if (mon.startsWith("lug")) return 7;
if (mon.startsWith("ago")) return 8;
if (mon.startsWith("set")) return 9;
if (mon.startsWith("ott")) return 10;
if (mon.startsWith("nov")) return 11;
if (mon.startsWith("dic")) return 12;
throw new RuntimeException("Could not find month '" + monthStr + "'");
}
}
View on GitHub (pinned to 2e990059ce)
Solutions
- Add or correct the missing month mapping in getMonth for the string shown in the message
- Normalize the input (lowercase, trim) before the prefix checks if the caller may pass mixed-case text
- Align the rule's regex alternation with exactly the prefixes handled in getMonth
Example fix
// before
if (mon.startsWith("dic")) return 12;
throw new RuntimeException("Could not find month '" + monthStr + "'");
// after
if (mon.startsWith("dic")) return 12;
throw new RuntimeException("Could not find month '" + monthStr + "'"); // ensure caller only passes recognized prefixes; e.g. normalize first
// or: if (mon.startsWith("gen")) return 1; // add missing month Defensive patterns
Strategy: validation
Validate before calling
Set<String> prefixes = Set.of("gen","feb","mar","apr","mag","giu","lug","ago","set","ott","nov","dic");
if (!prefixes.stream().anyMatch(monthStr.toLowerCase()::startsWith)) throw new IllegalArgumentException("Unrecognized Italian month: " + monthStr); Type guard
boolean isItalianMonth(String s) { String m = s == null ? "" : s.toLowerCase(); return m.length() >= 3 && Set.of("gen","feb","mar","apr","mag","giu","lug","ago","set","ott","nov","dic").stream().anyMatch(m::startsWith); } Try / catch
try { month = filter.getMonth(monthStr); } catch (RuntimeException e) { log.warn("Unknown month token: {}", monthStr); return null; } Prevention
- Write a parametrized test covering all Italian month forms your rule regex accepts
- Lowercase and trim input before prefix matching
- Document that Roman numerals are not accepted by getMonth
When it happens
Trigger: A rule passes a month string that does not start with one of the recognized Italian month prefixes (e.g. an English month 'mar' colliding is fine, but 'may', 'maggio' misspelled, or a Roman numeral like 'VII' which getMonth does not accept).
Common situations: Date rule regex extended to accept new month forms (Roman numerals, full genitive forms) without updating getMonth; locale-specific abbreviations differing from the hardcoded prefixes.
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
- Could not find day of week for '<dayStr>'
- Could not find day of week for '<dayStr>'
- Could not find month '<monthStr>'
- Could not find day of week for '<dayStr>'
- Could not find month '<monthStr>'
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/0eb9f67da90d8d1e.
Report an issue: GitHub.