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(String) maps Spanish day-of-week abbreviations/names ('lu', 'lunes', ... 'sábado') to java.util.Calendar constants. If the input string matches none of the recognized forms it throws RuntimeException. Note it recognizes 'lunes'..'sábado' but the day list omits 'domingo', so unexpected abbreviations fail.

Source

Thrown at languagetool-language-modules/es/src/main/java/org/languagetool/rules/es/DateFilterHelper.java:43

 * @since 4.3
 */
class DateFilterHelper {

  protected Calendar getCalendar() {
    return Calendar.getInstance(Locale.FRANCE);
  }

  @SuppressWarnings("ControlFlowStatementWithoutBraces")
  protected int getDayOfWeek(String dayStr) {
    String day = dayStr.toLowerCase();
    if (day.equals("do") || day.equals("domingo")) return Calendar.SUNDAY;
    if (day.equals("lu") || day.equals("lunes")) return Calendar.MONDAY;
    if (day.equals("ma") || day.equals("martes")) return Calendar.TUESDAY;
    if (day.equals("mi") || day.equals("miércoles")) return Calendar.WEDNESDAY;
    if (day.equals("ju") || day.equals("jueves")) return Calendar.THURSDAY;
    if (day.equals("vi") || day.equals("viernes")) return Calendar.FRIDAY;
    if (day.equals("sa") || day.equals("sábado")) return Calendar.SATURDAY;
    throw new RuntimeException("Could not find day of week for '" + dayStr + "'");
  }

  @SuppressWarnings("ControlFlowStatementWithoutBraces")
  protected String getDayOfWeek(Calendar date) {
    String englishDay = date.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.UK);
    if (englishDay.equals("Sunday")) return "domingo";
    if (englishDay.equals("Monday")) return "lunes";
    if (englishDay.equals("Tuesday")) return "martes";
    if (englishDay.equals("Wednesday")) return "miércoles";
    if (englishDay.equals("Thursday")) return "jueves";
    if (englishDay.equals("Friday")) return "viernes";
    if (englishDay.equals("Saturday")) return "sábado";
    return "";
  }

  @SuppressWarnings({"ControlFlowStatementWithoutBraces", "MagicNumber"})
  protected int getMonth(String monthStr) {
    String mon = monthStr.toLowerCase();

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Normalize the input before the call (lowercase, strip accents) and add missing accepted forms (e.g. 'do'/'domingo') to the mapping.
  2. Verify the rule's regex token is supposed to match a day; restrict the pattern to the supported day list.
  3. Add a unit test covering all day spellings the rule can capture.

Example fix

// before
if (day.equals("sa") || day.equals("sábado")) return Calendar.SATURDAY;
throw new RuntimeException("Could not find day of week for '" + dayStr + "'");
// after
if (day.equals("sa") || day.equals("sábado")) return Calendar.SATURDAY;
if (day.equals("do") || day.equals("domingo")) return Calendar.SUNDAY;
Defensive patterns

Strategy: validation

Validate before calling

Set<String> validDays = Set.of("lu","lunes","ma","martes","mi","miércoles","ju","jueves","vi","viernes","sa","sábado");
if (!validDays.contains(dayStr.toLowerCase())) throw new IllegalArgumentException("Unsupported day: " + dayStr);

Try / catch

try {
  int dow = helper.getDayOfWeek(dayStr);
} catch (RuntimeException e) {
  LOG.warn("Unrecognized day token '{}' — skipping date check", dayStr);
}

Prevention

When it happens

Trigger: A Spanish date rule filter calls getDayOfWeek(dayStr) with a captured token that is not one of lu/lunes, ma/martes, mi/miércoles, ju/jueves, vi/viernes, sa/sábado — e.g. 'do'/'domingo', 'miercoles' without accent, or 'L' uppercase variant.

Common situations: Rule regex captures a day token outside the whitelist; text uses 'domingo' while the mapping lacks it; accented vs unaccented spellings ('miercoles' vs 'miércoles').

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


AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06). Data as JSON: /api/errors/f9fac90a46dffd45. Report an issue: GitHub.