{"record":{"id":"95fc82f2772353fa","repo":"MyCATApache/Mycat-Server","slug":"mkdirs-failed-to-create-parentdir","errorCode":null,"errorMessage":"Mkdirs failed to create {parentDir}","messagePattern":"Mkdirs failed to create (.+?)","errorType":"exception","errorClass":"java.io.IOException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/config/classloader/JarLoader.java","lineNumber":25,"sourceCode":"import java.net.URLClassLoader;\r\nimport java.io.*;\r\nimport java.util.*;\r\n\r\npublic class JarLoader {\r\n\t  /** Unpack a jar file into a directory. */\r\n\t  public static void unJar(File jarFile, File toDir) throws IOException {\r\n\t    JarFile jar = new JarFile(jarFile);\r\n\t    try {\r\n\t      Enumeration entries = jar.entries();\r\n\t      while (entries.hasMoreElements()) {\r\n\t        JarEntry entry = (JarEntry)entries.nextElement();\r\n\t        if (!entry.isDirectory()) {\r\n\t          InputStream in = jar.getInputStream(entry);\r\n\t          try {\r\n\t            File file = new File(toDir, entry.getName());\r\n\t            if (!file.getParentFile().mkdirs() && !file.getParentFile().isDirectory()) {\r\n\r\n\t                throw new IOException(\"Mkdirs failed to create \" + \r\n\t                                      file.getParentFile().toString());\r\n\r\n\t            }\r\n\t            OutputStream out = new FileOutputStream(file);\r\n\t            try {\r\n\t              byte[] buffer = new byte[8192];\r\n\t              int i;\r\n\t              while ((i = in.read(buffer)) != -1) {\r\n\t                out.write(buffer, 0, i);\r\n\t              }\r\n\t            } finally {\r\n\t              out.close();\r\n\t            }\r\n\t          } finally {\r\n\t            in.close();\r\n\t          }\r\n\t        }\r\n\t      }\r","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/config/classloader/JarLoader.java#L7-L43","documentation":"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>').","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\ndir.mkdirs(); // silently fails on read-only fs\n// after\nif (!dir.exists() && !dir.mkdirs()) {\n    throw new IOException(\"Cannot create dir: \" + dir);\n}","handlingStrategy":"try-catch","validationCode":"File toDir = new File(target);\nif (!toDir.canWrite()) throw new IllegalStateException(\"No write access: \" + toDir);","typeGuard":null,"tryCatchPattern":"try {\n    loader.loadJar(path);\n} catch (IOException e) {\n    if (e.getMessage().startsWith(\"Mkdirs failed\")) {\n        // check permissions/ownership on extraction dir, then retry\n    }\n}","preventionTips":["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)"],"tags":["io","jar","filesystem","mkdir"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}