{"record":{"id":"af63d95732e6befd","repo":"languagetool-org/languagetool","slug":"could-not-find-month-monthstr-af63d9","errorCode":null,"errorMessage":"Could not find month '<monthStr>'","messagePattern":"Could not find month '<monthStr>'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"languagetool-language-modules/pt/src/main/java/org/languagetool/rules/pt/DateFilterHelper.java","lineNumber":76,"sourceCode":"    return \"\";\n  }\n\n  @SuppressWarnings({\"ControlFlowStatementWithoutBraces\", \"MagicNumber\"})\n  protected int getMonth(String monthStr) {\n    String mon = StringTools.trimSpecialCharacters(monthStr).toLowerCase();  // quickfix for special characters like soft hyphens\n    if (mon.startsWith(\"jan\")) return 1;\n    if (mon.startsWith(\"fev\")) return 2;\n    if (mon.startsWith(\"mar\")) return 3;\n    if (mon.startsWith(\"abr\")) return 4;\n    if (mon.startsWith(\"mai\")) return 5;\n    if (mon.startsWith(\"jun\")) return 6;\n    if (mon.startsWith(\"jul\")) return 7;\n    if (mon.startsWith(\"ago\")) return 8;\n    if (mon.startsWith(\"set\")) return 9;\n    if (mon.startsWith(\"out\")) return 10;\n    if (mon.startsWith(\"nov\")) return 11;\n    if (mon.startsWith(\"dez\")) return 12;\n    throw new RuntimeException(\"Could not find month '\" + monthStr + \"'\");\n  }\n}\n","sourceCodeStart":58,"sourceCodeEnd":79,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-language-modules/pt/src/main/java/org/languagetool/rules/pt/DateFilterHelper.java#L58-L79","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nif (mon.startsWith(\"dez\")) return 12;\nthrow new RuntimeException(\"Could not find month '\" + monthStr + \"'\");\n// after\nif (mon.startsWith(\"dez\")) return 12;\nif (mon.isEmpty()) throw new IllegalArgumentException(\"Month argument missing in rule match\");\nthrow new RuntimeException(\"Could not find month '\" + monthStr + \"'\");","handlingStrategy":"validation","validationCode":"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);","typeGuard":"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).*\"); }","tryCatchPattern":"try { month = helper.getMonth(monthStr); } catch (RuntimeException e) { log.warn(\"Portuguese month unmatched: {}\", monthStr); return null; }","preventionTips":["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"],"tags":["java","nlp","grammar-rules","date-validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}