{"record":{"id":"13c7ae3bfbeba00f","repo":"languagetool-org/languagetool","slug":"could-not-create","errorCode":null,"errorMessage":"Could not create: ","messagePattern":"Could not create: ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"languagetool-dev/src/main/java/org/languagetool/dev/bigdata/FrequencyIndexCreator.java","lineNumber":329,"sourceCode":"    public void close() throws Exception {\n      if (writer != null) {\n        writer.close();\n      }\n    }\n  }\n\n  static class TextDataWriter extends DataWriter {\n\n    private final FileWriter fw;\n    private final BufferedWriter writer;\n    \n    TextDataWriter(File indexDir) throws IOException {\n      if (indexDir.exists()) {\n        System.out.println(\"Using existing dir: \" + indexDir.getAbsolutePath());\n      } else {\n        boolean mkdir = indexDir.mkdir();\n        if (!mkdir) {\n          throw new RuntimeException(\"Could not create: \" + indexDir.getAbsolutePath());\n        }\n      }\n      fw = new FileWriter(new File(indexDir, indexDir.getName() + \"-output.csv\"));\n      writer = new BufferedWriter(fw);\n    }\n\n    @Override\n    void addDoc(String text, long count) throws IOException {\n      fw.write(text + \"\\t\" + count + \"\\n\");\n    }\n\n    @Override\n    void addTotalTokenCountDoc(long totalTokenCount) throws IOException {\n      System.err.println(\"Note: not writing totalTokenCount (\" + totalTokenCount + \") in file mode\");\n    }\n\n    @Override\n    public void close() throws Exception {","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-dev/src/main/java/org/languagetool/dev/bigdata/FrequencyIndexCreator.java#L311-L347","documentation":"TextDataWriter's constructor creates the per-file index directory and throws if File.mkdir() fails. mkdir() returns false when the parent directory is missing or not writable (it never creates parents). Subsequently it also opens a CSV writer in that directory.","triggerScenarios":"indexDir's parent does not exist so mkdir() returns false; no write permission on the parent; a race where another process creates the dir between exists() and mkdir().","commonSituations":"Passing a nested path like out/sub/dir without creating parents; running as a user without write access to the output base; concurrent runs colliding.","solutions":["Pre-create parent directories with mkdir -p (or use indexDir.mkdirs() in the code) before running","Ensure the process user has write permission on the parent directory","Re-run if a concurrent process was creating the same directory","Change the output path to an existing, writable location"],"exampleFix":"// before\nboolean mkdir = indexDir.mkdir();\n// after\nboolean mkdir = indexDir.mkdirs(); // creates missing parents\n// shell equivalent before running\nmkdir -p /data/index/output-dir","handlingStrategy":"validation","validationCode":"File indexDir = new File(path);\nFile parent = indexDir.getAbsoluteFile().getParentFile();\nif (parent == null || !parent.isDirectory() || !parent.canWrite()) {\n  throw new IllegalStateException(\"Parent not writable: \" + parent);\n}\nif (!indexDir.exists()) indexDir.mkdirs();","typeGuard":null,"tryCatchPattern":"try {\n  runIndexing(indexDir);\n} catch (RuntimeException e) {\n  if (e.getMessage().startsWith(\"Could not create\")) {\n    System.err.println(\"Fix permissions or create parent dirs for \" + indexDir);\n  }\n}","preventionTips":["Use mkdirs() instead of mkdir() when nested output paths are possible","Run the tool as a user with write access to the output base","Avoid concurrent runs writing to the same index path"],"tags":["mkdir","filesystem","permissions"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}