MyCATApache/Mycat-Server · error · java.io.IOException
Mkdirs failed to create
Error message
Mkdirs failed to create {parentDir} What it means
JarLoader.unJar extracts a jar's entries into a target directory; before writing each file it creates parent directories with File.mkdirs(). If mkdirs() returns false and the path is still not an existing directory, it throws IOException('Mkdirs failed to create <parentDir>').
Solutions
- Ensure the extraction (toDir) directory exists and is writable by the Mycat process user
- Remove any regular file that occupies the same path as a needed parent directory
- Check filesystem permissions/SELinux and disk space; verify path length limits are not exceeded
- Extract to a different writable directory
Example fix
// before
dir.mkdirs(); // silently fails on read-only fs
// after
if (!dir.exists() && !dir.mkdirs()) {
throw new IOException("Cannot create dir: " + dir);
} Defensive patterns
Strategy: try-catch
Validate before calling
File toDir = new File(target);
if (!toDir.canWrite()) throw new IllegalStateException("No write access: " + toDir); Try / catch
try {
loader.loadJar(path);
} catch (IOException e) {
if (e.getMessage().startsWith("Mkdirs failed")) {
// check permissions/ownership on extraction dir, then retry
}
} Prevention
- Run Mycat as a user that owns or can write the extraction directory
- Pre-create the extraction directory with correct permissions
- Keep target directories free of files that collide with jar entry names
- Monitor disk space and SELinux denials (audit log)
When it happens
Trigger: Extracting a jar (via loadJar) into a directory where parent folders cannot be created: no write permission on toDir, a file exists where a directory is needed, path too long, or read-only filesystem.
Common situations: Loading a user-defined jar from a read-only classpath directory; running Mycat as a user without write access to the extraction directory; SELinux/AppArmor restrictions; a stale file occupying the target path.
Understand the failure class
Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.
Related errors
- Error opening jar
- Failed to create local dir in $newDir.
- Failed to delete:
- Failed to list files for dir:
- Failed to create a temp directory
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/95fc82f2772353fa.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/config/classloader/JarLoader.java:25
import java.net.URLClassLoader;
import java.io.*;
import java.util.*;
public class JarLoader {
/** Unpack a jar file into a directory. */
public static void unJar(File jarFile, File toDir) throws IOException {
JarFile jar = new JarFile(jarFile);
try {
Enumeration entries = jar.entries();
while (entries.hasMoreElements()) {
JarEntry entry = (JarEntry)entries.nextElement();
if (!entry.isDirectory()) {
InputStream in = jar.getInputStream(entry);
try {
File file = new File(toDir, entry.getName());
if (!file.getParentFile().mkdirs() && !file.getParentFile().isDirectory()) {
throw new IOException("Mkdirs failed to create " +
file.getParentFile().toString());
}
OutputStream out = new FileOutputStream(file);
try {
byte[] buffer = new byte[8192];
int i;
while ((i = in.read(buffer)) != -1) {
out.write(buffer, 0, i);
}
} finally {
out.close();
}
} finally {
in.close();
}
}
}
View on GitHub (pinned to 65f8d8beb7)