languagetool-org/languagetool · error · RuntimeException

Chinese language expected, got <language>

Error message

Chinese language expected, got <language>

What it means

Chinese.getInstance() looks up the language registry by short code and requires the result to be an instance of Chinese. If the registry returns a different Language implementation (or nothing), it throws this RuntimeException. This indicates the Chinese language module is not registered as expected.

Source

Thrown at languagetool-language-modules/zh/src/main/java/org/languagetool/language/Chinese.java:118

  @Override
  public SentenceTokenizer createDefaultSentenceTokenizer() {
    return new ChineseSentenceTokenizer();
  }

  /** @since 3.1 */
  @Override
  public List<Rule> getRelevantLanguageModelRules(ResourceBundle messages, LanguageModel languageModel, UserConfig userConfig) throws IOException {
    return Collections.singletonList(
      new ChineseConfusionProbabilityRule(messages, languageModel, this)
    );
  }

  public static @NotNull Chinese getInstance() {
    Language language = Objects.requireNonNull(Languages.getLanguageForShortCode(LANGUAGE_SHORT_CODE));
    if (language instanceof Chinese chinese) {
      return chinese;
    }
    throw new RuntimeException("Chinese language expected, got " + language);
  }
}

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Ensure the Chinese language module jar is on the classpath
  2. Verify the language registry resources (language.properties style metadata) are not stripped by shading/minimization
  3. Call Languages.getLanguageForShortCode("zh") and log the returned class to diagnose the mismatch
  4. Rebuild with the zh module included

Example fix

// before
Chinese zh = Chinese.getInstance();
// after
Language lang = Languages.getLanguageForShortCode("zh");
if (!(lang instanceof Chinese)) {
  throw new IllegalStateException("zh module missing, got: " + lang.getClass());
}
Chinese zh = (Chinese) lang;
Defensive patterns

Strategy: validation

Validate before calling

Language lang = Languages.getLanguageForShortCode("zh");
if (lang == null || !(lang instanceof Chinese)) {
    throw new IllegalStateException("Chinese module missing from classpath");
}

Type guard

boolean chineseAvailable() {
    return Languages.getLanguageForShortCode("zh") instanceof Chinese;
}

Try / catch

try {
    Chinese zh = Chinese.getInstance();
} catch (RuntimeException e) {
    if (e.getMessage().startsWith("Chinese language expected")) {
        throw new IllegalStateException("Install languagetool-language-modules/zh jar", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling Chinese.getInstance() when the zh language module is not on the classpath so Languages.getLanguageForShortCode("zh") resolves to another class, or when LANGUAGE_SHORT_CODE maps to a non-Chinese Language.

Common situations: Deployments missing languagetool-language-modules/zh jar, or fat-jar shading that drops the language registration resource files.

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/f77eec57f022ad66. Report an issue: GitHub.