languagetool-org/languagetool · error · RuntimeException
LanguageModel directory not found or is not a directory:
Error message
LanguageModel directory not found or is not a directory:
What it means
setLanguageModelDirectory configures the n-gram LanguageModel directory used for better suggestions (e.g. for English/German). A RuntimeException is thrown when the supplied path does not exist or is a file rather than a directory.
Source
Thrown at languagetool-server/src/main/java/org/languagetool/server/HTTPServerConfig.java:561
throw new IllegalArgumentException("dictionary file does not exist or is not a file: '" + dictPath + "'");
}
ServerTools.print("Adding dynamic spell checker language " + name + ", code: " + code + ", dictionary: " + dictPath);
Language lang = Languages.addLanguage(name, code, new File(dictPath));
// better fail early in case of misconfiguration, so use the language now:
if (!new File(lang.getCommonWordsPath()).exists()) {
throw new IllegalArgumentException("Common words path not found: '" + lang.getCommonWordsPath() + "'");
}
JLanguageTool lt = new JLanguageTool(lang);
lt.check("test");
}
}
}
public void setLanguageModelDirectory(String langModelDir) {
SuggestionsOrdererConfig.setNgramsPath(langModelDir);
languageModelDir = new File(langModelDir);
if (!languageModelDir.exists() || !languageModelDir.isDirectory()) {
throw new RuntimeException("LanguageModel directory not found or is not a directory: " + languageModelDir);
}
}
void setFasttextPaths(String fasttextModelPath, String fasttextBinaryPath) {
fasttextModel = new File(fasttextModelPath);
fasttextBinary = new File(fasttextBinaryPath);
if (!fasttextModel.exists() || fasttextModel.isDirectory()) {
throw new RuntimeException("Fasttext model path not valid (file doesn't exist or is a directory): " + fasttextModelPath);
}
if (!fasttextBinary.exists() || fasttextBinary.isDirectory() || !fasttextBinary.canExecute()) {
throw new RuntimeException("Fasttext binary path not valid (file doesn't exist, is a directory or not executable): " + fasttextBinaryPath);
}
}
/*
* @param verbose if true, the text to be checked will be displayed in case of exceptions
*/
public boolean isVerbose() {View on GitHub (pinned to 2e990059ce)
Solutions
- Download and unzip the n-grams data for the language and pass the extracted directory path
- Verify with `ls -ld <path>` that the path exists and is a directory
- Fix the --languageModel argument or config property to the correct directory
Example fix
// before --languageModel /opt/ngrams-en.zip // after --languageModel /opt/ngrams-en
Defensive patterns
Strategy: validation
Validate before calling
File dir = new File(langModelDir);
if (!dir.isDirectory())
throw new IllegalStateException("LanguageModel dir missing: " + langModelDir); Try / catch
try {
config.setLanguageModelDir(modelDir);
} catch (RuntimeException e) {
LOG.error("Bad languageModel dir: {}", e.getMessage());
} Prevention
- Download and extract n-gram data before starting the server
- Point at the extracted directory, not the zip
- Verify with `ls -ld` in your startup script before launch
When it happens
Trigger: Calling setLanguageModelDirectory(path) (directly or via the --languageModel server option) with a path that is absent on disk or points to a regular file.
Common situations: Forgetting to download/extract the n-grams dataset before starting the server, pointing at the zip archive instead of the extracted directory, or a typo in the path.
Related errors
- dictionary file does not exist or is not a file: ''
- Common words path not found: ''
- Fasttext model path not valid (file doesn't exist or is a di
- Fasttext binary path not valid (file doesn't exist, is a dir
- <dir.getAbsolutePath()> is not a directory, cannot use recur
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/306b887bc3b19c16.
Report an issue: GitHub.