{"record":{"id":"c34f4ee71f8f8647","repo":"languagetool-org/languagetool","slug":"output-directory-already-exists","errorCode":null,"errorMessage":"Output directory already exists: ","messagePattern":"Output directory already exists: ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"languagetool-dev/src/main/java/org/languagetool/dev/bigdata/TextIndexCreator.java","lineNumber":81,"sourceCode":"        doc.add(new TextField(Lucene.FIELD_NAME, line, Field.Store.YES));\n        doc.add(new TextField(Lucene.FIELD_NAME_LOWERCASE, line.toLowerCase(), Field.Store.YES));\n        indexWriter.addDocument(doc);\n        if (++lineCount % 10_000 == 0) {\n          System.out.println(lineCount + \"...\");\n        }\n      }\n    }\n  }\n\n  public static void main(String[] args) throws IOException {\n    if (args.length < 2) {\n      System.out.println(\"Usage: \" + TextIndexCreator.class.getSimpleName() + \" <outputDir> <inputFile...>\");\n      System.exit(0);\n    }\n    TextIndexCreator creator = new TextIndexCreator();\n    File outputDir = new File(args[0]);\n    if (outputDir.exists()) {\n      throw new RuntimeException(\"Output directory already exists: \" + outputDir);\n    }\n    creator.index(outputDir, Arrays.copyOfRange(args, 1, args.length));\n  }\n  \n}\n","sourceCodeStart":63,"sourceCodeEnd":87,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-dev/src/main/java/org/languagetool/dev/bigdata/TextIndexCreator.java#L63-L87","documentation":"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.","triggerScenarios":"Re-running the tool with the same outputDir argument without deleting the previous run's directory; pointing at an existing directory by mistake.","commonSituations":"Re-running after a failed/interrupted previous run; scripted retries that reuse args; accidentally using a directory that already holds data.","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"],"exampleFix":"// before\njava TextIndexCreator /data/out corpus.txt   // /data/out exists from previous run\n// after\nrm -rf /data/out && java TextIndexCreator /data/out corpus.txt\n// or: java TextIndexCreator /data/out-$(date +%s) corpus.txt","handlingStrategy":"validation","validationCode":"File outputDir = new File(args[0]);\nif (outputDir.exists()) {\n  throw new IllegalStateException(\"Output dir exists, remove or choose another: \" + outputDir);\n}","typeGuard":null,"tryCatchPattern":"try {\n  TextIndexCreator.main(args);\n} catch (RuntimeException e) {\n  if (e.getMessage().startsWith(\"Output directory already exists\")) {\n    System.err.println(\"Delete \" + args[0] + \" or pick a fresh output dir\");\n  }\n}","preventionTips":["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"],"tags":["file-exists","cli","overwrite-protection"],"backgroundTag":"file-already-exists","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"}