{"record":{"id":"51c584a1e4286596","repo":"MuntashirAkon/AppManager","slug":"could-not-create-directory","errorCode":null,"errorMessage":"Could not create directory ","messagePattern":"Could not create directory ","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/io/PathImpl.java","lineNumber":1350,"sourceCode":"        Uri parentUri = Paths.removeLastPathSegment(mountPoint);\n        return new PathImpl(context, parentUri).documentFile;\n    }\n\n    @NonNull\n    private static DocumentFile createArbitraryDirectories(@NonNull DocumentFile documentFile,\n                                                           @NonNull String[] names,\n                                                           int length) throws IOException {\n        DocumentFile file = getRealDocumentFile(documentFile);\n        for (int i = 0; i < length; ++i) {\n            Path fsRoot = VirtualFileSystem.getFsRoot(Paths.appendPathSegment(file.getUri(), names[i]));\n            DocumentFile t = fsRoot != null ? fsRoot.documentFile : file.findFile(names[i]);\n            if (t == null) {\n                t = file.createDirectory(names[i]);\n            } else if (!t.isDirectory()) {\n                throw new IOException(t.getUri() + \" exists and it is not a directory.\");\n            }\n            if (t == null) {\n                throw new IOException(\"Could not create directory \" + file.getUri() + File.separatorChar + names[i]);\n            }\n            file = t;\n        }\n        return file;\n    }\n\n    @NonNull\n    private static DocumentFile getRealDocumentFile(@NonNull DocumentFile documentFile) {\n        Path fsRoot = VirtualFileSystem.getFsRoot(documentFile.getUri());\n        if (fsRoot != null) {\n            return fsRoot.documentFile;\n        }\n        return documentFile;\n    }\n\n    @Nullable\n    private static DocumentFile resolveFileOrNull(@NonNull DocumentFile documentFile) {\n        DocumentFile realDocumentFile = getRealDocumentFile(documentFile);","sourceCodeStart":1332,"sourceCodeEnd":1368,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/io/PathImpl.java#L1332-L1368","documentation":"Thrown by PathImpl's mkdirs helper when DocumentsProvider.createDirectory() returns null for an intermediate segment, i.e. the provider could not materialize the directory. Note the null-check is unreachable in practice because createDirectory failure is usually signalled another way; it guards against providers that return null.","triggerScenarios":"Calling Path.createDirectories(...) where a segment cannot be created by the provider — read-only volume, invalid/illegal segment name for the provider, storage full, or provider bug returning null.","commonSituations":"Creating directories on read-only external storage; segment names with characters the provider rejects (trailing dots/spaces on some providers); low-storage devices; legacy AccessStorageFramework quirks.","solutions":["Check parent.canWrite() before creating the chain","Sanitize each segment name (avoid trailing dots/spaces and illegal characters)","Verify free space and storage permissions","Catch IOException and log the segment + parent URI from the message to identify the failing level"],"exampleFix":"// before\ndir.createDirectories(dirName);\n// after\nif (!dir.canWrite()) throw new IOException(\"Cannot write in \" + dir);\nString safe = dirName.replaceAll(\"[\\\\u0000/.]+$\", \"\");\ndir.createDirectories(safe);","handlingStrategy":"try-catch","validationCode":"if (!dir.canWrite()) throw new IOException(\"Cannot create directories in \" + dir);","typeGuard":"boolean canMkdir(Path base, String seg) { return base.isDirectory() && base.canWrite() && !seg.isEmpty(); }","tryCatchPattern":"try { dir.createDirectories(chain); } catch (IOException e) { throw new IOException(\"Provider failed to create directory chain under \" + dir, e); }","preventionTips":["Sanitize segment names (strip trailing dots/spaces, illegal chars)","Check canWrite() on the base directory first","Verify free storage before bulk directory creation"],"tags":["android","io","mkdir","saf"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}