{"record":{"id":"207e9b6183ec7b63","repo":"apache/hadoop","slug":"mkdirs-failed-to-create-parent-getabsolutepath","errorCode":null,"errorMessage":"Mkdirs failed to create \" + parent.getAbsolutePath()","messagePattern":"Mkdirs failed to create \" \\+ parent\\.getAbsolutePath\\(\\)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java","lineNumber":756,"sourceCode":"   */\n  public static void unZip(InputStream inputStream, File toDir)\n      throws IOException {\n    try (ZipArchiveInputStream zip = new ZipArchiveInputStream(inputStream)) {\n      int numOfFailedLastModifiedSet = 0;\n      String targetDirPath = toDir.getCanonicalPath() + File.separator;\n      for(ZipArchiveEntry entry = zip.getNextZipEntry();\n          entry != null;\n          entry = zip.getNextZipEntry()) {\n        if (!entry.isDirectory()) {\n          File file = new File(toDir, entry.getName());\n          if (!file.getCanonicalPath().startsWith(targetDirPath)) {\n            throw new IOException(\"expanding \" + entry.getName()\n                + \" would create file outside of \" + toDir);\n          }\n          File parent = file.getParentFile();\n          if (!parent.mkdirs() &&\n              !parent.isDirectory()) {\n            throw new IOException(\"Mkdirs failed to create \" +\n                parent.getAbsolutePath());\n          }\n          try (OutputStream out = Files.newOutputStream(file.toPath())) {\n            IOUtils.copyBytes(zip, out, BUFFER_SIZE);\n          }\n          if (!file.setLastModified(entry.getTime())) {\n            numOfFailedLastModifiedSet++;\n          }\n          if (entry.getPlatform() == ZipArchiveEntry.PLATFORM_UNIX) {\n            Files.setPosixFilePermissions(file.toPath(), permissionsFromMode(entry.getUnixMode()));\n          }\n        }\n      }\n      if (numOfFailedLastModifiedSet > 0) {\n        LOG.warn(\"Could not set last modfied time for {} file(s)\",\n            numOfFailedLastModifiedSet);\n      }\n    }","sourceCodeStart":738,"sourceCodeEnd":774,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java#L738-L774","documentation":"Inside unZip(InputStream, File toDir), after the path-traversal check passes, the code creates the entry's parent directory; if parent.mkdirs() returns false AND parent.isDirectory() is still false it throws IOException(\"Mkdirs failed to create <parent.getAbsolutePath()>\"). The isDirectory() re-check makes it tolerant of concurrent creation, so the throw means the directory genuinely could not be created or exists as a file. It is an environment/permissions failure, not an archive-content issue.","triggerScenarios":"Extraction target on a read-only filesystem; a regular file already exists at the parent path the archive wants as a directory; SELinux/AppArmor denial; disk/inode exhaustion; NFS mount permissions.","commonSituations":"Extracting into /tmp with noexec/locked-down ACLs; leftover file from a previous partial extraction blocking a needed directory; containers with read-only layers; disk-full CI runners.","solutions":["Clear the blocked path: delete the stale FILE occupying the parent directory location, then retry unZip","Verify the target is writable and has space before extracting: toDir.canWrite(), Files.getFileStore(...).getUsableSpace()","Extract into a fresh empty directory (unique per run) to avoid collisions with prior runs","Fix filesystem-level denials: mount options (rw,exec), SELinux policy, ownership of toDir"],"exampleFix":"// before\nFileUtil.unZip(zipStream, new File(\"/opt/app\")); // Mkdirs failed to create /opt/app/lib\n// because /opt/app/lib exists as a FILE\n\n// after\nFile blocked = new File(\"/opt/app/lib\");\nif (blocked.exists() && !blocked.isDirectory()) {\n  Files.delete(blocked.toPath());\n}\nFileUtil.unZip(zipStream, new File(\"/opt/app\"));","handlingStrategy":"validation","validationCode":"if (!toDir.canWrite()) throw new IOException(\"Extraction dir not writable: \" + toDir);\nlong usable = Files.getFileStore(toDir.getCanonicalFile().toPath()).getUsableSpace();\nif (usable < neededBytes) throw new IOException(\"Insufficient space: \" + usable);","typeGuard":null,"tryCatchPattern":"try {\n  FileUtil.unZip(in, toDir);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Mkdirs failed\")) {\n    // check for a blocking FILE at the parent path and clear it, then retry once\n  } else throw e;\n}","preventionTips":["Extract into a fresh empty directory per run","Clear stale files left by failed extractions that can occupy directory paths","Check writability, SELinux context, and free space before extraction"],"tags":["mkdir-failed","unzip","permissions","disk-full","archive-extraction"],"backgroundTag":"mkdir-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}