languagetool-org/languagetool · error · RuntimeException

Could not get rules of language <language>

Error message

Could not get rules of language <language>

What it means

getAllBuiltinRules asks the Language for its relevant rules via getRelevantRules and getRelevantRulesGlobalConfig; these can throw IOException while loading resources. Such an IOException is wrapped in this RuntimeException naming the language. It means the language's builtin rule set could not be retrieved.

Source

Thrown at languagetool-core/src/main/java/org/languagetool/JLanguageTool.java:527

    return ResourceBundleTools.getMessageBundle();
  }

  /**
   * Gets the ResourceBundle (i18n strings) for the given user interface language.
   *
   * @since 2.4 (public since 2.4)
   */
  public static ResourceBundle getMessageBundle(Language lang) {
    return ResourceBundleTools.getMessageBundle(lang);
  }

  private List<Rule> getAllBuiltinRules(Language language, ResourceBundle messages, UserConfig userConfig, GlobalConfig globalConfig) {
    try {
      List<Rule> rules = new ArrayList<>(language.getRelevantRules(messages, userConfig, motherTongue, altLanguages));
      rules.addAll(language.getRelevantRulesGlobalConfig(messages, globalConfig, userConfig, motherTongue, altLanguages));
      return rules;
    } catch (IOException e) {
      throw new RuntimeException("Could not get rules of language " + language, e);
    }
  }

  /**
   * Set a PrintStream that will receive verbose output. Set to
   * {@code null} (which is the default) to disable verbose output.
   */
  public void setOutput(PrintStream printStream) {
    this.printStream = printStream;
    GlobalConfig.setVerbose(printStream != null);
  }

  /**
   * Load pattern rules from an XML file. Use {@link #addRule(Rule)} to add these
   * rules to the checking process.
   *
   * @param filename path to an XML file in the classpath or in the filesystem - the classpath is checked first
   * @return a List of {@link PatternRule} objects

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Check the wrapped IOException's message for the missing/unreadable resource path.
  2. Verify the language module jar is complete and on the classpath (unzip -l to confirm rule XMLs).
  3. Run with a clean, matching-version set of LanguageTool artifacts (core + language modules).
  4. For custom languages, ensure resource streams are correctly packaged inside the jar.

Example fix

// before (custom language resource read from working dir)
InputStream s = new FileInputStream("rules.xml");
// after (package resource in jar and read via classloader)
InputStream s = getClass().getResourceAsStream("/org/languagetool/rules/rules.xml");
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure the language module jar contains its rule resources
URL res = getClass().getResource("/org/languagetool/rules/<lang>/grammar.xml");
if (res == null) throw new IllegalStateException("language rule resources missing from classpath");

Try / catch

try {
  lt = new JLanguageTool(language);
} catch (RuntimeException e) {
  if (e.getCause() instanceof IOException io) {
    logger.error("Missing/unreadable rule resource for " + language + ": " + io.getMessage());
  }
  throw e;
}

Prevention

When it happens

Trigger: Creating any JLanguageTool instance when the language's getRelevantRules(...) throws IOException — typically a missing or unreadable internal resource (rule XML, spelling dictionaries) for that language.

Common situations: Incomplete jar/classpath (language resources stripped by shading or packaging); read-permission problems on resource files; custom Language whose rule-loading code throws IOException.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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