{"record":{"id":"242f6fca10701325","repo":"apache/druid","slug":"failed-to-create-temporary-directory-in-path-s","errorCode":null,"errorMessage":"Failed to create temporary directory in path [%s]","messagePattern":"Failed to create temporary directory in path \\[(.+?)\\]","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/java/util/common/FileUtils.java","lineNumber":493,"sourceCode":"  public static File createTempDirInLocation(final Path parentDirectory, @Nullable final String prefix)\n  {\n    try {\n      final Path tmpPath = Files.createTempDirectory(\n          parentDirectory,\n          prefix == null || prefix.isEmpty() ? \"druid\" : prefix\n      );\n      return tmpPath.toFile();\n    }\n    catch (IOException e) {\n      // Some inspection to improve error messages.\n      if (e instanceof NoSuchFileException && !parentDirectory.toFile().exists()) {\n        throw new ISE(\"Path [%s] does not exist\", parentDirectory);\n      } else if ((e instanceof FileSystemException && e.getMessage().contains(\"Read-only file system\"))\n                 || (e instanceof AccessDeniedException)) {\n        throw new ISE(\"Path [%s] is not writable, check permissions\", parentDirectory);\n      } else {\n        // Well, maybe it was something else.\n        throw new ISE(e, \"Failed to create temporary directory in path [%s]\", parentDirectory);\n      }\n    }\n  }\n\n  /**\n   * Create \"directory\" and all intermediate directories as needed. If the directory is successfully created, or already\n   * exists, returns quietly. Otherwise, throws an IOException.\n   *\n   * Simpler to use than {@link File#mkdirs()}, and more reliable since it is safe from races where two threads try\n   * to create the same directory at the same time.\n   *\n   * The name is inspired by UNIX {@code mkdir -p}, which has the same behavior.\n   */\n  @SuppressForbidden(reason = \"File#mkdirs\")\n  public static void mkdirp(final File directory) throws IOException\n  {\n    // isDirectory check after mkdirs is necessary in case of concurrent calls to mkdirp, because two concurrent\n    // calls to mkdirs cannot both succeed.","sourceCodeStart":475,"sourceCodeEnd":511,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/common/FileUtils.java#L475-L511","documentation":"FileUtils.createTempDirInLocation throws this ISE with the IOException attached when creating a temp directory fails for a reason other than a missing parent, read-only filesystem, or access denial. It is the catch-all branch of the temp-directory creation error handling and preserves the original cause for diagnosis.","triggerScenarios":"Calling FileUtils.createTempDir/createTempDirInLocation when the underlying atomic directory creation throws an IOException not classified as NoSuchFileException, AccessDeniedException, or read-only FileSystemException (e.g. device full in a way surfaced differently, I/O errors, path exists as a file, name too long).","commonSituations":"Parent path exists but is a regular file, not a directory; filesystem errors or corruption; exceeding filename/path length limits; out of inodes or disk-full conditions; exotic filesystems rejecting atomic mkdir.","solutions":["Read the attached cause (ISE wraps the IOException) to see the real filesystem error","Check whether the parent path is a regular file instead of a directory; remove or rename it","Check disk space and inode availability (df -h, df -i) on the target filesystem","Point the temp-dir setting at a different, healthy filesystem","If the message hints at path length, use a shorter base path"],"exampleFix":"// before\nFile tmp = FileUtils.createTempDir(new File(\"/data/persist\")); // /data/persist is a file\n// after\n// remove the stray file and ensure /data/persist is a directory\nnew File(\"/data/persist\").delete();\nFiles.createDirectories(Paths.get(\"/data/persist\"));\nFile tmp = FileUtils.createTempDir(new File(\"/data/persist\"));","handlingStrategy":"try-catch","validationCode":"File parent = new File(path);\nif (!parent.exists()) Files.createDirectories(parent.toPath());\nif (!parent.isDirectory()) throw new IllegalStateException(\"Parent is not a directory: \" + path);\nif (!parent.canWrite()) throw new IllegalStateException(\"Parent not writable: \" + path);","typeGuard":"static boolean isValidTempParent(File dir) {\n  return dir != null && dir.isDirectory() && dir.canWrite();\n}","tryCatchPattern":"try {\n  File tmp = FileUtils.createTempDir(parent);\n} catch (ISE e) {\n  throw new RuntimeException(\"Temp dir creation failed in \" + parent + \": \" + e.getCause(), e);\n}","preventionTips":["Always inspect getCause() — this ISE wraps the real IOException","Ensure the parent path is a directory, not a file","Monitor disk space and inodes on the temp filesystem","Keep temp base paths short to avoid path-length limits"],"tags":["filesystem","io","temp-directory"],"backgroundTag":"file-write-failed","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}