languagetool-org/languagetool · error · RuntimeException

Could not tag and disambiguate '<token>'

Error message

Could not tag and disambiguate '<token>'

What it means

RussianPartialPosTagFilter.tag() tags a single token with the Russian tagger and runs the disambiguator; if any step throws an IOException (typically while loading dictionaries or tagger resources), it is wrapped in this unchecked RuntimeException. It indicates the POS-tagging/disambiguation pipeline failed for the given token, not that the token is linguistically invalid.

Source

Thrown at languagetool-language-modules/ru/src/main/java/org/languagetool/rules/ru/RussianPartialPosTagFilter.java:49

/**
 * A {@link PartialPosTagFilter} for Russian that also runs the disambiguator. Note
 * that the disambiguator is called with a single token, so only rules
 * will apply that have a single {@code <match>} element.
 *
 * @since 3.6
 */
public class RussianPartialPosTagFilter extends PartialPosTagFilter {

  @Override
  protected List<AnalyzedTokenReadings> tag(String token) {
    try {
      var russianLanguage = Russian.getInstance();
      List<AnalyzedTokenReadings> tags = russianLanguage.getTagger().tag(Collections.singletonList(token));
      AnalyzedTokenReadings[] atr = tags.toArray(new AnalyzedTokenReadings[tags.size()]);
      AnalyzedSentence disambiguated = russianLanguage.getDisambiguator().disambiguate(new AnalyzedSentence(atr));
      return Arrays.asList(disambiguated.getTokens());
    } catch (IOException e) {
      throw new RuntimeException("Could not tag and disambiguate '" + token + "'", e);
    }
  }
}

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Verify the Russian language module (languagetool-language-modules/ru) and its dictionary resources are on the classpath and intact.
  2. Inspect the wrapped IOException cause (getCause()) to find the real resource/IO failure.
  3. If a custom dictionary path is configured, confirm the files exist and are readable by the process.
  4. Rebuild/redeploy the jar if resources were stripped by build packaging rules.

Example fix

// before: IOException bubbles as bare RuntimeException
catch (IOException e) {
  throw new RuntimeException("Could not tag and disambiguate '" + token + "'", e);
}
// after: fail fast with a clear resource check before tagging
var russianLanguage = Russian.getInstance();
Objects.requireNonNull(token, "token must not be null");
try {
  List<AnalyzedTokenReadings> tags = russianLanguage.getTagger().tag(Collections.singletonList(token));
  ...
} catch (IOException e) {
  throw new RuntimeException("Could not tag and disambiguate '" + token + "': dictionary resources missing or unreadable", e);
}
Defensive patterns

Strategy: try-catch

Validate before calling

boolean resourcesAvailable = getClass().getResource("/org/languagetool/resource/ru/") != null;
if (!resourcesAvailable) { throw new IllegalStateException("Russian dictionary resources missing from classpath"); }

Try / catch

try {
  List<AnalyzedTokenReadings> result = filter.tag(token);
} catch (RuntimeException e) {
  Throwable cause = e.getCause(); // IOException from tagger/disambiguator
  logger.warn("Tagging failed for token '{}': {}", token, cause != null ? cause.getMessage() : e.getMessage());
  // fall back to untagged token or skip the rule
}

Prevention

When it happens

Trigger: Calling tag(String) on RussianPartialPosTagFilter when the underlying Russian tagger or disambiguator throws IOException — e.g. dictionary resource files missing or unreadable, malformed user dictionaries, or I/O errors reading language module resources.

Common situations: Running LanguageTool in a packaged/deployed environment where Russian dictionary resources were not included in the classpath; corrupted or partially extracted .jar files; custom-user-directory configurations pointing to missing dictionary paths.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


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