languagetool-org/languagetool · error · RuntimeException

Месец '<monthStr>' не постоји.

Error message

Месец '<monthStr>' не постоји.

What it means

DateCheckFilter for Serbian maps a month token (Serbian month name/inflected form or Roman numeral like 'VII') to a month number. If the string matches none of the accepted names, abbreviations, or Roman numerals, getMonth throws this RuntimeException indicating an unrecognized month value.

Source

Thrown at languagetool-language-modules/sr/src/main/java/org/languagetool/rules/sr/DateCheckFilter.java:73

  }

  @SuppressWarnings({"ControlFlowStatementWithoutBraces", "MagicNumber"})
  @Override
  protected int getMonth(String monthStr) {
    String mon = monthStr.toLowerCase();
    if (mon.equals("јануар") || monthStr.equals("I") || mon.equals("јануара") || mon.equals("јан")) return 1;
    if (mon.equals("фебруар") || monthStr.equals("II") || mon.equals("фебруара") || mon.equals("феб")) return 2;
    if (mon.equals("март") || monthStr.equals("III") || mon.equals("марта") || mon.equals("мар")) return 3;
    if (mon.equals("април") || monthStr.equals("IV") || mon.equals("априла") || mon.equals("апр")) return 4;
    if (mon.equals("мај") || monthStr.equals("V") || mon.equals("маја")) return 5;
    if (mon.equals("јун") || monthStr.equals("VI") || mon.equals("јуна") || mon.equals("јун")) return 6;
    if (mon.equals("јул") || monthStr.equals("VII") || mon.equals("јула") || mon.equals("јул")) return 7;
    if (mon.equals("август") || monthStr.equals("VIII") || mon.equals("августа") || mon.equals("авг")) return 8;
    if (mon.equals("септембар") || monthStr.equals("IX") || mon.equals("септембра") || mon.equals("сеп")) return 9;
    if (mon.equals("октобар") || monthStr.equals("X") || mon.equals("октобра") || mon.equals("окт")) return 10;
    if (mon.equals("новембар") || monthStr.equals("XI") || mon.equals("новембра") || mon.equals("нов")) return 11;
    if (mon.equals("децембар") || monthStr.equals("XII") || mon.equals("децембра") || mon.equals("дец")) return 12;
    throw new RuntimeException("Месец '" + monthStr + "' не постоји.");
  }
}

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Verify the month string is one of the accepted Serbian names/abbreviations or Roman numerals I–XII.
  2. Normalize case and trim whitespace before calling the filter.
  3. If Latin-script dates must be supported, add the missing Latin month forms to getMonth.
  4. Validate the month token in the calling rule before invoking DateCheckFilter.

Example fix

// before: unguarded call
int month = filter.getMonth(monthStr);
// after: normalize and pre-validate
String mon = monthStr.trim().toLowerCase(Locale.forLanguageTag("sr"));
Set<String> known = Set.of("јануар","фебруар","март","април","мај","јун","јул","август","септембар","октобар","новембар","децембар");
if (!known.contains(mon) && !mon.matches("^(?i)(I|II|III|IV|V|VI|VII|VIII|IX|X|XI|XII)$")) {
  throw new IllegalArgumentException("Unrecognized month: " + monthStr);
}
Defensive patterns

Strategy: validation

Validate before calling

private static final Set<String> SR_MONTHS = Set.of("јануар","фебруар","март","април","мај","јун","јул","август","септембар","октобар","новембар","децембар");
boolean isRecognizedSerbianMonth(String monthStr) {
  String m = monthStr == null ? "" : monthStr.trim().toLowerCase(Locale.forLanguageTag("sr"));
  return SR_MONTHS.contains(m) || m.matches("^(?i)(I|II|III|IV|V|VI|VII|VIII|IX|X|XI|XII)$");
}

Try / catch

try {
  int month = filter.getMonth(monthStr);
} catch (RuntimeException e) {
  logger.warn("Unrecognized Serbian month token: {}", monthStr);
  // reject the date match
}

Prevention

When it happens

Trigger: Passing a month string such as 'maj' (Latin for May, not covered), an unrecognized abbreviation, wrong case ('Јул'), a Latin-script form when only Cyrillic entries exist, or an out-of-range Roman numeral into getMonth.

Common situations: Rules matching dates written in Latin Serbian script while the filter's month list only covers Cyrillic forms; month names in genitive forms not listed (e.g. 'јула' is listed but others may not cover all inflections); typos in custom grammar rules.

Related errors


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