apache/hadoop · error · IOException
Mkdirs failed to create " + parent.getAbsolutePath()
Error message
Mkdirs failed to create " + parent.getAbsolutePath()
What it means
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.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java:756
*/
public static void unZip(InputStream inputStream, File toDir)
throws IOException {
try (ZipArchiveInputStream zip = new ZipArchiveInputStream(inputStream)) {
int numOfFailedLastModifiedSet = 0;
String targetDirPath = toDir.getCanonicalPath() + File.separator;
for(ZipArchiveEntry entry = zip.getNextZipEntry();
entry != null;
entry = zip.getNextZipEntry()) {
if (!entry.isDirectory()) {
File file = new File(toDir, entry.getName());
if (!file.getCanonicalPath().startsWith(targetDirPath)) {
throw new IOException("expanding " + entry.getName()
+ " would create file outside of " + toDir);
}
File parent = file.getParentFile();
if (!parent.mkdirs() &&
!parent.isDirectory()) {
throw new IOException("Mkdirs failed to create " +
parent.getAbsolutePath());
}
try (OutputStream out = Files.newOutputStream(file.toPath())) {
IOUtils.copyBytes(zip, out, BUFFER_SIZE);
}
if (!file.setLastModified(entry.getTime())) {
numOfFailedLastModifiedSet++;
}
if (entry.getPlatform() == ZipArchiveEntry.PLATFORM_UNIX) {
Files.setPosixFilePermissions(file.toPath(), permissionsFromMode(entry.getUnixMode()));
}
}
}
if (numOfFailedLastModifiedSet > 0) {
LOG.warn("Could not set last modfied time for {} file(s)",
numOfFailedLastModifiedSet);
}
}View on GitHub (pinned to 2add963021)
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
Example fix
// before
FileUtil.unZip(zipStream, new File("/opt/app")); // Mkdirs failed to create /opt/app/lib
// because /opt/app/lib exists as a FILE
// after
File blocked = new File("/opt/app/lib");
if (blocked.exists() && !blocked.isDirectory()) {
Files.delete(blocked.toPath());
}
FileUtil.unZip(zipStream, new File("/opt/app")); Defensive patterns
Strategy: validation
Validate before calling
if (!toDir.canWrite()) throw new IOException("Extraction dir not writable: " + toDir);
long usable = Files.getFileStore(toDir.getCanonicalFile().toPath()).getUsableSpace();
if (usable < neededBytes) throw new IOException("Insufficient space: " + usable); Try / catch
try {
FileUtil.unZip(in, toDir);
} catch (IOException e) {
if (e.getMessage() != null && e.getMessage().startsWith("Mkdirs failed")) {
// check for a blocking FILE at the parent path and clear it, then retry once
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Mkdirs failed to create " + file.getParentFile().toString()
- Mkdirs failed to create " + untarDir
- Mkdirs failed to create tar internal dir " + outputDir
- Cannot create directory ${aliasMapFile}
- expanding " + entry.getName() + " would create file outside
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/207e9b6183ec7b63.
Report an issue: GitHub.