languagetool-org/languagetool · error · RuntimeException
Could not find day of week for '" + dayStr + "'
Error message
Could not find day of week for '" + dayStr + "'
What it means
DateFilterHelper.getDayOfWeek maps French weekday strings (lun.., mar.., mer.., jeu.., ven.., sam..) to java.util.Calendar constants. When none of the startsWith prefixes match, it throws this RuntimeException because the weekday argument of a date rule could not be interpreted.
Source
Thrown at languagetool-language-modules/fr/src/main/java/org/languagetool/rules/fr/DateFilterHelper.java:43
* @since 4.3
*/
class DateFilterHelper {
protected Calendar getCalendar() {
return Calendar.getInstance(Locale.FRENCH);
}
@SuppressWarnings("ControlFlowStatementWithoutBraces")
protected int getDayOfWeek(String dayStr) {
String day = dayStr.toLowerCase();
if (day.startsWith("dim")) return Calendar.SUNDAY;
if (day.startsWith("lun")) return Calendar.MONDAY;
if (day.startsWith("mar")) return Calendar.TUESDAY;
if (day.startsWith("mer")) return Calendar.WEDNESDAY;
if (day.startsWith("jeu")) return Calendar.THURSDAY;
if (day.startsWith("ven")) return Calendar.FRIDAY;
if (day.startsWith("sam")) return Calendar.SATURDAY;
throw new RuntimeException("Could not find day of week for '" + dayStr + "'");
}
protected String getDayOfWeek(Calendar date) {
return date.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.FRENCH);
}
@SuppressWarnings({"ControlFlowStatementWithoutBraces", "MagicNumber"})
protected int getMonth(String monthStr) {
String mon = monthStr.toLowerCase();
if (mon.startsWith("jan")) return 1;
if (mon.startsWith("fév")) return 2;
if (mon.startsWith("fev")) return 2;
if (mon.startsWith("mar")) return 3;
if (mon.startsWith("avr")) return 4;
if (mon.startsWith("mai")) return 5;
// "juin" and "juillet" are never abbreviated with 3 letters
// since it would be ambiguous (both start with "jui").View on GitHub (pinned to 2e990059ce)
Solutions
- Fix the rule argument to a French weekday covered by the filter (lundi..samedi).
- If 'dimanche' (Sunday) is needed, extend getDayOfWeek with `if (day.startsWith("dim")) return Calendar.SUNDAY;` before the throw.
- Normalize the input (lowercase, trim, expand abbreviations) before calling the filter.
Example fix
// before
if (day.startsWith("sam")) return Calendar.SATURDAY;
throw new RuntimeException("Could not find day of week for '" + dayStr + "'");
// after
if (day.startsWith("sam")) return Calendar.SATURDAY;
if (day.startsWith("dim")) return Calendar.SUNDAY;
throw new RuntimeException("Could not find day of week for '" + dayStr + "'"); Defensive patterns
Strategy: validation
Validate before calling
Set<String> validPrefixes = Set.of("lun","mar","mer","jeu","ven","sam");
String d = dayStr == null ? "" : dayStr.toLowerCase().trim();
if (validPrefixes.stream().noneMatch(d::startsWith)) {
throw new IllegalArgumentException("Unsupported weekday: " + dayStr);
} Try / catch
try { int dow = helper.getDayOfWeek(cal); } catch (RuntimeException e) { LOG.warn("Unmapped weekday: " + e.getMessage()); } Prevention
- Only pass French weekday names covered by the prefix list.
- Patch getDayOfWeek to include 'dim' (Sunday) if dimanche rules are used.
- Lowercase and trim weekday args before the filter runs.
When it happens
Trigger: A French grammar rule passes a 'weekDay'-like argument whose lowercase value does not start with lun/mar/mer/jeu/ven/sam — e.g. 'dim' (dimanche, which is not in the list), misspellings, English weekday names, or empty string.
Common situations: Sunday: rules referencing 'dimanche' hit the gap in the prefix table; abbreviations with unusual casing handled upstream differently; translations of rules from other languages carry non-French weekday words.
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 month '" + monthStr + "'
- Could not find day of week for '" + dayStr + "'
- Could not find month '" + monthStr + "'
- Set only 'weekDay' and 'date' for " + DMYDateCheckFilter.cla
- Expected date in format 'dd-mm-yyyy': '" + dateString + "'
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/f2e92e3292348d96.
Report an issue: GitHub.