languagetool-org/languagetool · error

Could not create:

Error message

Could not create: 

What it means

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.

Source

Thrown at languagetool-dev/src/main/java/org/languagetool/dev/bigdata/FrequencyIndexCreator.java:329

    public void close() throws Exception {
      if (writer != null) {
        writer.close();
      }
    }
  }

  static class TextDataWriter extends DataWriter {

    private final FileWriter fw;
    private final BufferedWriter writer;
    
    TextDataWriter(File indexDir) throws IOException {
      if (indexDir.exists()) {
        System.out.println("Using existing dir: " + indexDir.getAbsolutePath());
      } else {
        boolean mkdir = indexDir.mkdir();
        if (!mkdir) {
          throw new RuntimeException("Could not create: " + indexDir.getAbsolutePath());
        }
      }
      fw = new FileWriter(new File(indexDir, indexDir.getName() + "-output.csv"));
      writer = new BufferedWriter(fw);
    }

    @Override
    void addDoc(String text, long count) throws IOException {
      fw.write(text + "\t" + count + "\n");
    }

    @Override
    void addTotalTokenCountDoc(long totalTokenCount) throws IOException {
      System.err.println("Note: not writing totalTokenCount (" + totalTokenCount + ") in file mode");
    }

    @Override
    public void close() throws Exception {

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Pre-create parent directories with mkdir -p (or use indexDir.mkdirs() in the code) before running
  2. Ensure the process user has write permission on the parent directory
  3. Re-run if a concurrent process was creating the same directory
  4. Change the output path to an existing, writable location

Example fix

// before
boolean mkdir = indexDir.mkdir();
// after
boolean mkdir = indexDir.mkdirs(); // creates missing parents
// shell equivalent before running
mkdir -p /data/index/output-dir
Defensive patterns

Strategy: validation

Validate before calling

File indexDir = new File(path);
File parent = indexDir.getAbsoluteFile().getParentFile();
if (parent == null || !parent.isDirectory() || !parent.canWrite()) {
  throw new IllegalStateException("Parent not writable: " + parent);
}
if (!indexDir.exists()) indexDir.mkdirs();

Try / catch

try {
  runIndexing(indexDir);
} catch (RuntimeException e) {
  if (e.getMessage().startsWith("Could not create")) {
    System.err.println("Fix permissions or create parent dirs for " + indexDir);
  }
}

Prevention

When it happens

Trigger: 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().

Common situations: 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.

Understand the failure class

Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.

Related errors


AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06). Data as JSON: /api/errors/13c7ae3bfbeba00f. Report an issue: GitHub.