{"record":{"id":"bc15666801e90d3b","repo":"languagetool-org/languagetool","slug":"could-not-find-day-of-week-for-daystr-bc1566","errorCode":null,"errorMessage":"Could not find day of week for '<dayStr>'","messagePattern":"Could not find day of week for '<dayStr>'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"languagetool-language-modules/it/src/main/java/org/languagetool/rules/it/DateCheckFilter.java","lineNumber":48,"sourceCode":"public class DateCheckFilter extends AbstractDateCheckFilter {\n\n  @Override\n  protected Calendar getCalendar() {\n    return Calendar.getInstance(Locale.UK);\n  }\n\n  @SuppressWarnings(\"ControlFlowStatementWithoutBraces\")\n  @Override\n  protected int getDayOfWeek(String dayStr) {\n    String day = dayStr.toLowerCase();\n    if (day.startsWith(\"do\") || day.equals(\"domenica\")) return Calendar.SUNDAY;\n    if (day.startsWith(\"lu\") || day.equals(\"lunedì\")) return Calendar.MONDAY;\n    if (day.startsWith(\"ma\") || day.equals(\"martedì\")) return Calendar.TUESDAY;\n    if (day.startsWith(\"me\") || day.equals(\"mercoledì\")) return Calendar.WEDNESDAY;\n    if (day.startsWith(\"gi\") || day.equals(\"giovedì\")) return Calendar.THURSDAY;\n    if (day.startsWith(\"ve\") || day.equals(\"venerdì\")) return Calendar.FRIDAY;\n    if (day.startsWith(\"sa\") || day.equals(\"sabato\")) return Calendar.SATURDAY;\n    throw new RuntimeException(\"Could not find day of week for '\" + dayStr + \"'\");\n  }\n\n  @SuppressWarnings(\"ControlFlowStatementWithoutBraces\")\n  @Override\n  protected String getDayOfWeek(Calendar date) {\n    String englishDay = date.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.UK);\n    if (englishDay.equals(\"Sunday\")) return \"domenica\";\n    if (englishDay.equals(\"Monday\")) return \"lunedì\";\n    if (englishDay.equals(\"Tuesday\")) return \"martedì\";\n    if (englishDay.equals(\"Wednesday\")) return \"mercoledì\";\n    if (englishDay.equals(\"Thursday\")) return \"giovedì\";\n    if (englishDay.equals(\"Friday\")) return \"venerdì\";\n    if (englishDay.equals(\"Saturday\")) return \"sabato\";\n    return \"\";\n  }\n\n  @SuppressWarnings({\"ControlFlowStatementWithoutBraces\", \"MagicNumber\"})\n  @Override","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-language-modules/it/src/main/java/org/languagetool/rules/it/DateCheckFilter.java#L30-L66","documentation":"DateCheckFilter for Italian validates that a day-of-week found in text matches a recognized Italian weekday name or abbreviation. getDayOfWeek throws this RuntimeException when the extracted day string matches none of the known prefixes (lu, ma, me, gi, ve, sa) or full names. The filter assumes the regex that feeds it only matches valid weekdays, so an unmatched string indicates the rule regex and the filter are out of sync.","triggerScenarios":"A grammar rule matches a token as a weekday and passes it to getDayOfWeek, but the token is not one of lunedì/lu, martedì/ma, mercoledì/me, giovedì/gi, venerdì/ve, sabato/sa (e.g. 'dom' or 'domenica', which has no mapping — Sunday is missing from the chain).","commonSituations":"Text contains 'domenica' (Sunday) matched by the date rule but the mapping has no Sunday branch; adding new Italian weekday spellings or abbreviations to the rule regex without updating getDayOfWeek; case/accents normalized differently than expected.","solutions":["Add the missing day mapping (notably Sunday: if (day.startsWith(\"do\") || day.equals(\"domenica\")) return Calendar.SUNDAY;) to getDayOfWeek","Check the exception message for the exact day string and verify how the calling rule's regex captured it (case, accents, partial word)","Ensure the rule regex only matches tokens covered by the mapping, or make matching case-insensitive/accent-aware before lookup"],"exampleFix":"// before\nif (day.startsWith(\"sa\") || day.equals(\"sabato\")) return Calendar.SATURDAY;\nthrow new RuntimeException(\"Could not find day of week for '\" + dayStr + \"'\");\n// after\nif (day.startsWith(\"sa\") || day.equals(\"sabato\")) return Calendar.SATURDAY;\nif (day.startsWith(\"do\") || day.equals(\"domenica\")) return Calendar.SUNDAY;\nthrow new RuntimeException(\"Could not find day of week for '\" + dayStr + \"'\");","handlingStrategy":"validation","validationCode":"Set<String> known = Set.of(\"lu\",\"ma\",\"me\",\"gi\",\"ve\",\"sa\",\"lunedì\",\"martedì\",\"mercoledì\",\"giovedì\",\"venerdì\",\"sabato\");\nString d = dayStr.toLowerCase();\nif (!known.stream().anyMatch(d::startsWith)) throw new IllegalArgumentException(\"Unrecognized Italian weekday: \" + dayStr);","typeGuard":"boolean isItalianWeekday(String s) { String d = s == null ? \"\" : s.toLowerCase(); return d.startsWith(\"lu\")||d.startsWith(\"ma\")||d.startsWith(\"me\")||d.startsWith(\"gi\")||d.startsWith(\"ve\")||d.startsWith(\"sa\"); }","tryCatchPattern":"try { cal.set(Calendar.DAY_OF_WEEK, filter.getDayOfWeek(dayStr)); } catch (RuntimeException e) { log.warn(\"Unknown weekday token: {}\", dayStr); /* skip rule match */ }","preventionTips":["Keep the rule regex alternation and getDayOfWeek branches in sync; add a unit test enumerating every weekday form the regex can emit","Include Sunday ('dom'/'domenica') coverage tests — it is absent in the current chain","Normalize case and accents 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-14T00:17:10.932Z"}