{"record":{"id":"f77eec57f022ad66","repo":"languagetool-org/languagetool","slug":"chinese-language-expected-got-language","errorCode":null,"errorMessage":"Chinese language expected, got <language>","messagePattern":"Chinese language expected, got <language>","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"languagetool-language-modules/zh/src/main/java/org/languagetool/language/Chinese.java","lineNumber":118,"sourceCode":"  @Override\n  public SentenceTokenizer createDefaultSentenceTokenizer() {\n    return new ChineseSentenceTokenizer();\n  }\n\n  /** @since 3.1 */\n  @Override\n  public List<Rule> getRelevantLanguageModelRules(ResourceBundle messages, LanguageModel languageModel, UserConfig userConfig) throws IOException {\n    return Collections.singletonList(\n      new ChineseConfusionProbabilityRule(messages, languageModel, this)\n    );\n  }\n\n  public static @NotNull Chinese getInstance() {\n    Language language = Objects.requireNonNull(Languages.getLanguageForShortCode(LANGUAGE_SHORT_CODE));\n    if (language instanceof Chinese chinese) {\n      return chinese;\n    }\n    throw new RuntimeException(\"Chinese language expected, got \" + language);\n  }\n}\n","sourceCodeStart":100,"sourceCodeEnd":121,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-language-modules/zh/src/main/java/org/languagetool/language/Chinese.java#L100-L121","documentation":"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.","triggerScenarios":"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.","commonSituations":"Deployments missing languagetool-language-modules/zh jar, or fat-jar shading that drops the language registration resource files.","solutions":["Ensure the Chinese language module jar is on the classpath","Verify the language registry resources (language.properties style metadata) are not stripped by shading/minimization","Call Languages.getLanguageForShortCode(\"zh\") and log the returned class to diagnose the mismatch","Rebuild with the zh module included"],"exampleFix":"// before\nChinese zh = Chinese.getInstance();\n// after\nLanguage lang = Languages.getLanguageForShortCode(\"zh\");\nif (!(lang instanceof Chinese)) {\n  throw new IllegalStateException(\"zh module missing, got: \" + lang.getClass());\n}\nChinese zh = (Chinese) lang;","handlingStrategy":"validation","validationCode":"Language lang = Languages.getLanguageForShortCode(\"zh\");\nif (lang == null || !(lang instanceof Chinese)) {\n    throw new IllegalStateException(\"Chinese module missing from classpath\");\n}","typeGuard":"boolean chineseAvailable() {\n    return Languages.getLanguageForShortCode(\"zh\") instanceof Chinese;\n}","tryCatchPattern":"try {\n    Chinese zh = Chinese.getInstance();\n} catch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"Chinese language expected\")) {\n        throw new IllegalStateException(\"Install languagetool-language-modules/zh jar\", e);\n    }\n    throw e;\n}","preventionTips":["Ship the zh language module jar with the server","Check shaded jars retain language registration metadata resources","Probe Languages.getLanguageForShortCode(\"zh\") at startup as a health check","Pin consistent LanguageTool module versions"],"tags":["java","classpath","languagetool","language-registration"],"backgroundTag":"resource-not-found","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}