{"record":{"id":"7d2db7e53b68326e","repo":"apache/hadoop","slug":"mkdirs-failed-to-create-file-getparentfile-t","errorCode":null,"errorMessage":"Mkdirs failed to create \" + file.getParentFile().toString()","messagePattern":"Mkdirs failed to create \" \\+ file\\.getParentFile\\(\\)\\.toString\\(\\)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java","lineNumber":846,"sourceCode":"    Enumeration<? extends ZipArchiveEntry> entries;\n    ZipFile zipFile = new ZipFile(inFile);\n\n    try {\n      entries = zipFile.getEntries();\n      String targetDirPath = unzipDir.getCanonicalPath() + File.separator;\n      while (entries.hasMoreElements()) {\n        ZipArchiveEntry entry = entries.nextElement();\n        if (!entry.isDirectory()) {\n          InputStream in = zipFile.getInputStream(entry);\n          try {\n            File file = new File(unzipDir, entry.getName());\n            if (!file.getCanonicalPath().startsWith(targetDirPath)) {\n              throw new IOException(\"expanding \" + entry.getName()\n                  + \" would create file outside of \" + unzipDir);\n            }\n            if (!file.getParentFile().mkdirs()) {\n              if (!file.getParentFile().isDirectory()) {\n                throw new IOException(\"Mkdirs failed to create \" +\n                                      file.getParentFile().toString());\n              }\n            }\n            OutputStream out = Files.newOutputStream(file.toPath());\n            try {\n              byte[] buffer = new byte[8192];\n              int i;\n              while ((i = in.read(buffer)) != -1) {\n                out.write(buffer, 0, i);\n              }\n            } finally {\n              out.close();\n            }\n            if (entry.getPlatform() == ZipArchiveEntry.PLATFORM_UNIX) {\n              Files.setPosixFilePermissions(file.toPath(), permissionsFromMode(entry.getUnixMode()));\n            }\n          } finally {\n            in.close();","sourceCodeStart":828,"sourceCodeEnd":864,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java#L828-L864","documentation":"In unZip(File inFile, File unzipDir), after the traversal check, file.getParentFile().mkdirs() returning false with a subsequent isDirectory()==false triggers IOException(\"Mkdirs failed to create <parent>\"). Note this variant checks mkdirs() first and only then verifies isDirectory(), the inverse order of the stream variant — behaviorally equivalent: the parent directory for an entry could not be established. Environment failure, not archive content.","triggerScenarios":"unzipDir on a read-only mount; an existing regular file where the archive needs a directory; permission denied for the extracting user; out of space/inodes.","commonSituations":"Extracting to system paths (/usr, /opt) without root; leftover files from earlier failed extractions; restricted container filesystems; NFS/samba mounts with wrong uid mapping.","solutions":["Remove the blocking regular file at the parent path or choose a clean extraction directory","Confirm write permission and free space for unzipDir before starting","Run extraction with an account that owns unzipDir, or chown/chmod it appropriately","Retry with a fresh unique target dir per invocation"],"exampleFix":"// before\nFileUtil.unZip(zipFile, new File(\"/srv/data\")); // Mkdirs failed to create /srv/data/conf\n\n// after\nFile target = Files.createDirectories(\n    Paths.get(\"/srv/data/extract-\" + System.currentTimeMillis())).toFile();\nFileUtil.unZip(zipFile, target);","handlingStrategy":"validation","validationCode":"File target = new File(\"/srv/extract-\" + UUID.randomUUID());\nFiles.createDirectories(target.toPath()); // throws precise errors on failure\nFileUtil.unZip(inFile, target);","typeGuard":null,"tryCatchPattern":"try {\n  FileUtil.unZip(inFile, unzipDir);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Mkdirs failed\")) {\n    // inspect the named parent path: usually a stale FILE or permission denial\n  } else throw e;\n}","preventionTips":["Pre-create extraction roots with Files.createDirectories to get real OS error messages","Ensure the extracting user owns or can write unzipDir","Clean partial extractions before retrying"],"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"}