{"record":{"id":"c87bdfa48c93b756","repo":"stanfordnlp/CoreNLP","slug":"could-not-create-dir","errorCode":null,"errorMessage":"Could not create ${dir}","messagePattern":"Could not create (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/io/FileSystem.java","lineNumber":127,"sourceCode":"    \n    return firstLine.length() > 0;\n  }\n  \n  /**\n   * Make the given directory or throw a RuntimeException\n   */\n  public static void mkdirOrFail(String dir) {\n    mkdirOrFail(new File(dir));\n  }\n\n  /**\n   * Make the given directory or throw a RuntimeException\n   */\n  public static void mkdirOrFail(File dir) {\n    if (!dir.mkdirs()) {\n      String error = \"Could not create \" + dir;\n      log.info(error);\n      throw new RuntimeException(error);\n    }\n  }\n\n  public static void checkExistsOrFail(File file) {\n    if (!file.exists()) {\n      String error = \"Output path \" + file + \" does not exist\";\n      log.info(error);\n      throw new RuntimeException(error);\n    }\n  }\n\n  public static void checkNotExistsOrFail(File file) {\n    if (file.exists()) {\n      String error = \"Output path \" + file + \" already exists\";\n      log.info(error);\n      throw new RuntimeException(error);\n    }\n  }","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/io/FileSystem.java#L109-L145","documentation":"FileSystem.mkdirOrFail() calls File.mkdirs() and throws RuntimeException if it returns false, after logging the failure. Java's mkdirs() returns false when the directory (and any needed parents) could not be created.","triggerScenarios":"Calling mkdirOrFail(dir) when a parent path component exists as a regular file, the user lacks write permission on the parent, the path is invalid for the OS, or the directory already exists as a non-directory.","commonSituations":"Output directories on read-only mounts or containers; a stale file occupying the target path; typos in absolute paths (/vs missing drive); running as unprivileged user expecting to write to system paths.","solutions":["Check/write permissions on the parent directory; run with sufficient privileges or pick a writable path.","Verify no regular file exists at the target path (or a parent component); remove/rename it.","Confirm the path is valid on the OS (illegal characters, length limits).","Use plain File.mkdirs() with your own error handling if failure should be tolerated."],"exampleFix":"// before\nFileSystem.mkdirOrFail(new File(\"/data\")); // no permission\n// after\nFile dir = new File(\"/data\");\nif (!dir.exists() && !dir.mkdirs()) {\n  throw new IllegalStateException(\"Cannot create \" + dir + \" in cwd=\" + new File(\".\").getAbsolutePath());\n}","handlingStrategy":"validation","validationCode":"File parent = dir.getAbsoluteFile().getParentFile();\nif (parent != null && !parent.canWrite()) throw new IllegalStateException(\"Cannot write in \" + parent);\nif (dir.exists() && !dir.isDirectory()) throw new IllegalStateException(\"Occupied by file: \" + dir);","typeGuard":null,"tryCatchPattern":"try {\n  FileSystem.mkdirOrFail(dir);\n} catch (RuntimeException e) {\n  log.severe(\"mkdir failed for \" + dir + \": \" + e.getMessage());\n}","preventionTips":["Log absolute paths and the process user to debug permission issues","Avoid read-only mounts for output dirs","Check no file occupies a parent path component"],"tags":["file-io","mkdir","permissions"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}