languagetool-org/languagetool · error
Output directory already exists:
Error message
Output directory already exists:
What it means
TextIndexCreator.main refuses to run when the target output directory already exists, throwing this RuntimeException. It is an overwrite-safety guard: indexing appends many files and the tool avoids silently mixing with a previous run's output.
Source
Thrown at languagetool-dev/src/main/java/org/languagetool/dev/bigdata/TextIndexCreator.java:81
doc.add(new TextField(Lucene.FIELD_NAME, line, Field.Store.YES));
doc.add(new TextField(Lucene.FIELD_NAME_LOWERCASE, line.toLowerCase(), Field.Store.YES));
indexWriter.addDocument(doc);
if (++lineCount % 10_000 == 0) {
System.out.println(lineCount + "...");
}
}
}
}
public static void main(String[] args) throws IOException {
if (args.length < 2) {
System.out.println("Usage: " + TextIndexCreator.class.getSimpleName() + " <outputDir> <inputFile...>");
System.exit(0);
}
TextIndexCreator creator = new TextIndexCreator();
File outputDir = new File(args[0]);
if (outputDir.exists()) {
throw new RuntimeException("Output directory already exists: " + outputDir);
}
creator.index(outputDir, Arrays.copyOfRange(args, 1, args.length));
}
}
View on GitHub (pinned to 2e990059ce)
Solutions
- Delete or rename the existing output directory before re-running
- Use a new, unique output directory name for each run
- In automation, use rm -rf or a timestamped directory when a rerun is intentional
Example fix
// before java TextIndexCreator /data/out corpus.txt // /data/out exists from previous run // after rm -rf /data/out && java TextIndexCreator /data/out corpus.txt // or: java TextIndexCreator /data/out-$(date +%s) corpus.txt
Defensive patterns
Strategy: validation
Validate before calling
File outputDir = new File(args[0]);
if (outputDir.exists()) {
throw new IllegalStateException("Output dir exists, remove or choose another: " + outputDir);
} Try / catch
try {
TextIndexCreator.main(args);
} catch (RuntimeException e) {
if (e.getMessage().startsWith("Output directory already exists")) {
System.err.println("Delete " + args[0] + " or pick a fresh output dir");
}
} Prevention
- Use timestamped or UUID output directory names in scripts
- Clean up failed run directories before retrying
- Check target directory existence in your launcher script before invoking the tool
When it happens
Trigger: Re-running the tool with the same outputDir argument without deleting the previous run's directory; pointing at an existing directory by mistake.
Common situations: Re-running after a failed/interrupted previous run; scripted retries that reuse args; accidentally using a directory that already holds data.
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- WrongParameterNumberException
- Unknown level '<level>' - currently, only 'PICKY' is support
- You cannot list unknown words when tagging only
- You cannot apply suggestions when tagging only
- You cannot specify both disabled rules and enabledonly
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/c34f4ee71f8f8647.
Report an issue: GitHub.