languagetool-org/languagetool · error · RuntimeException
Could not create LanguageTool instance for language
Error message
Could not create LanguageTool instance for language <language>
What it means
Main.changeLanguage builds a MultiThreadedJLanguageTool for the requested language and selects rules; any Exception there is rethrown as this RuntimeException. It means the LanguageTool instance for the given language code could not be constructed or its rules could not be selected.
Solutions
- Check the 'Caused by' exception for the real initialization failure.
- Verify the language code with `languagetool --list` or the supported-languages list for your version.
- Remove/verify --enable and --disable rule ids; confirm they exist for the chosen language.
- Reinstall/upgrade LanguageTool if language resources are missing from the distribution.
Example fix
// before languagetool -l eng -c UTF-8 file.txt // after languagetool -l en-US -c UTF-8 file.txt
Defensive patterns
Strategy: validation
Validate before calling
Language lang = Languages.getLanguageForShortCode(langCode); // throws early if unsupported // also verify rule ids exist: // lt.getRuleForId(...) or check --list output before running
Try / catch
try {
Language lang = Languages.getLanguageForShortCode(code);
} catch (IllegalArgumentException e) {
System.err.println("Unsupported language code: " + code);
System.exit(2);
} Prevention
- Validate language short codes with Languages.getLanguageForShortCode before use.
- Keep all LanguageTool artifacts on one version.
- Verify --enable/--disable ids against the language's rule list.
When it happens
Trigger: Calling the CLI with a -l/--language value whose Language instance fails initialization, or with --disable/--enable rule ids that make Tools.selectRules throw (e.g. a rule id referencing something invalid), or mother-tongue lookup failing.
Common situations: Unsupported or misspelled language code on the command line; corrupted/incomplete language resource deployment; enabling/disabling rules that don't exist for that language in that version.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Could not activate rules
- Could not check text in file
- Could not load language model capable rules.
- Applying suggestions makes no sense for profiling
- Cannot use --premiumAlways with non-premium version
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/c3e232bf7035f80a.
Report an issue: GitHub.
Appendix: source
Thrown at languagetool-commandline/src/main/java/org/languagetool/commandline/Main.java:362
String fileContents = readerToString(reader);
if (xmlFiltering) {
return filterXML(fileContents);
} else {
return fileContents;
}
}
}
private void changeLanguage(Language language, Language motherTongue,
List<String> disabledRules, List<String> enabledRules) {
try {
lt = new MultiThreadedJLanguageTool(language, motherTongue);
Tools.selectRules(lt, disabledRules, enabledRules, true);
if (options.isVerbose()) {
lt.setOutput(System.err);
}
} catch (Exception e) {
throw new RuntimeException("Could not create LanguageTool instance for language " + language, e);
}
}
@FunctionalInterface
interface SystemExitHandler {
void exit(int status);
SystemExitHandler DEFAULT = System::exit;
}
static SystemExitHandler exitHandler = SystemExitHandler.DEFAULT;
/**
* Command line tool to check plain text files.
*/
public static void main(String[] args) throws IOException, ParserConfigurationException, SAXException {
JnaTools.setBugWorkaroundProperty();
CommandLineParser commandLineParser = new CommandLineParser();
CommandLineOptions options = null;View on GitHub (pinned to 2e990059ce)