languagetool-org/languagetool · error
Could not find month '<monthStr>'
Error message
Could not find month '<monthStr>'
What it means
Portuguese DateFilterHelper.getMonth maps Portuguese month prefixes (jan, fev, mar, abr, mai, jun, jul, ago, set, out, nov, dez) to month numbers and throws this RuntimeException when no prefix matches. It is called by getMonthFromArguments, which extracts the month argument from a rule match before calling it.
Source
Thrown at languagetool-language-modules/pt/src/main/java/org/languagetool/rules/pt/DateFilterHelper.java:76
return "";
}
@SuppressWarnings({"ControlFlowStatementWithoutBraces", "MagicNumber"})
protected int getMonth(String monthStr) {
String mon = StringTools.trimSpecialCharacters(monthStr).toLowerCase(); // quickfix for special characters like soft hyphens
if (mon.startsWith("jan")) return 1;
if (mon.startsWith("fev")) return 2;
if (mon.startsWith("mar")) return 3;
if (mon.startsWith("abr")) return 4;
if (mon.startsWith("mai")) return 5;
if (mon.startsWith("jun")) return 6;
if (mon.startsWith("jul")) return 7;
if (mon.startsWith("ago")) return 8;
if (mon.startsWith("set")) return 9;
if (mon.startsWith("out")) return 10;
if (mon.startsWith("nov")) return 11;
if (mon.startsWith("dez")) return 12;
throw new RuntimeException("Could not find month '" + monthStr + "'");
}
}
View on GitHub (pinned to 2e990059ce)
Solutions
- Add or correct the mapping for the prefix shown in the message (e.g. accept 'oct' alongside 'out' if desired)
- Verify the rule's regex actually captures the full month token (empty capture groups are a common cause)
- Lowercase/trim the argument before the prefix checks
Example fix
// before
if (mon.startsWith("dez")) return 12;
throw new RuntimeException("Could not find month '" + monthStr + "'");
// after
if (mon.startsWith("dez")) return 12;
if (mon.isEmpty()) throw new IllegalArgumentException("Month argument missing in rule match");
throw new RuntimeException("Could not find month '" + monthStr + "'"); Defensive patterns
Strategy: validation
Validate before calling
if (monthStr == null || monthStr.isBlank() || !monthStr.toLowerCase().matches("(jan|fev|mar|abr|mai|jun|jul|ago|set|out|nov|dez).*")) throw new IllegalArgumentException("Unrecognized Portuguese month: " + monthStr); Type guard
boolean isPortugueseMonth(String s) { String m = s == null ? "" : s.toLowerCase(); return m.length() >= 3 && m.matches("(jan|fev|mar|abr|mai|jun|jul|ago|set|out|nov|dez).*"); } Try / catch
try { month = helper.getMonth(monthStr); } catch (RuntimeException e) { log.warn("Portuguese month unmatched: {}", monthStr); return null; } Prevention
- Check that the rule regex's month capture group actually matched (empty captures flow into getMonth)
- Test all 12 month abbreviations through getMonthFromArguments
- Lowercase and trim arguments before lookup
When it happens
Trigger: getMonthFromArguments passes a month string that does not start with any recognized Portuguese prefix (e.g. English 'oct', Romanian-style forms, Roman numerals, or empty string when the rule failed to capture the month group).
Common situations: Rule regex month group not matching, yielding an empty or partial token; Brazilian vs European Portuguese abbreviation differences; adding new month forms to the rule without updating the helper.
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 month '<monthStr>'
- Could not find day of week for '<dayStr>'
- Could not find month '<monthStr>'
- Could not find day of week for '<dayStr>'
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/af63d95732e6befd.
Report an issue: GitHub.