apache/hadoop · error · IOException
Mkdirs failed to create " + file.getParentFile().toString()
Error message
Mkdirs failed to create " + file.getParentFile().toString()
What it means
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.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java:846
Enumeration<? extends ZipArchiveEntry> entries;
ZipFile zipFile = new ZipFile(inFile);
try {
entries = zipFile.getEntries();
String targetDirPath = unzipDir.getCanonicalPath() + File.separator;
while (entries.hasMoreElements()) {
ZipArchiveEntry entry = entries.nextElement();
if (!entry.isDirectory()) {
InputStream in = zipFile.getInputStream(entry);
try {
File file = new File(unzipDir, entry.getName());
if (!file.getCanonicalPath().startsWith(targetDirPath)) {
throw new IOException("expanding " + entry.getName()
+ " would create file outside of " + unzipDir);
}
if (!file.getParentFile().mkdirs()) {
if (!file.getParentFile().isDirectory()) {
throw new IOException("Mkdirs failed to create " +
file.getParentFile().toString());
}
}
OutputStream out = Files.newOutputStream(file.toPath());
try {
byte[] buffer = new byte[8192];
int i;
while ((i = in.read(buffer)) != -1) {
out.write(buffer, 0, i);
}
} finally {
out.close();
}
if (entry.getPlatform() == ZipArchiveEntry.PLATFORM_UNIX) {
Files.setPosixFilePermissions(file.toPath(), permissionsFromMode(entry.getUnixMode()));
}
} finally {
in.close();View on GitHub (pinned to 2add963021)
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
Example fix
// before
FileUtil.unZip(zipFile, new File("/srv/data")); // Mkdirs failed to create /srv/data/conf
// after
File target = Files.createDirectories(
Paths.get("/srv/data/extract-" + System.currentTimeMillis())).toFile();
FileUtil.unZip(zipFile, target); Defensive patterns
Strategy: validation
Validate before calling
File target = new File("/srv/extract-" + UUID.randomUUID());
Files.createDirectories(target.toPath()); // throws precise errors on failure
FileUtil.unZip(inFile, target); Try / catch
try {
FileUtil.unZip(inFile, unzipDir);
} catch (IOException e) {
if (e.getMessage() != null && e.getMessage().startsWith("Mkdirs failed")) {
// inspect the named parent path: usually a stale FILE or permission denial
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Extracting to system paths (/usr, /opt) without root; leftover files from earlier failed extractions; restricted container filesystems; NFS/samba mounts with wrong uid mapping.
Related errors
- Mkdirs failed to create " + parent.getAbsolutePath()
- 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/7d2db7e53b68326e.
Report an issue: GitHub.