{"record":{"id":"f1044fe88a512ccb","repo":"MuntashirAkon/AppManager","slug":"directory","errorCode":null,"errorMessage":"Directory","messagePattern":"Directory","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/io/PathImpl.java","lineNumber":453,"sourceCode":"        if (dirNames.length == 0) {\n            throw new IllegalArgumentException(\"Display name is empty\");\n        }\n        for (String name : dirNames) {\n            if (name.equals(\"..\")) {\n                throw new IOException(\"Could not create directories in the parent directory.\");\n            }\n        }\n        DocumentFile file = createArbitraryDirectories(documentFile, dirNames, dirNames.length - 1);\n        // Special case for the last segment\n        String lastSegment = dirNames[dirNames.length - 1];\n        Path fsRoot = VirtualFileSystem.getFsRoot(Paths.appendPathSegment(file.getUri(), lastSegment));\n        DocumentFile t = fsRoot != null ? fsRoot.documentFile : file.findFile(lastSegment);\n        if (t != null) {\n            throw new IOException(t.getUri() + \" already exists.\");\n        }\n        t = file.createDirectory(lastSegment);\n        if (t == null) {\n            throw new IOException(\"Directory\" + file.getUri() + File.separator + lastSegment + \" could not be created.\");\n        }\n        return new PathImpl(context, t);\n    }\n\n    @Nullable\n    public Path getParent() {\n        DocumentFile file = getRealDocumentFile(documentFile).getParentFile();\n        return file == null ? null : new PathImpl(context, file);\n    }\n\n    public boolean hasFile(@NonNull String displayName) {\n        return findFileInternal(documentFile, displayName) != null;\n    }\n\n    @NonNull\n    public Path findFile(@NonNull String displayName) throws FileNotFoundException {\n        DocumentFile nextPath = findFileInternal(documentFile, displayName);\n        if (nextPath == null) {","sourceCodeStart":435,"sourceCodeEnd":471,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/io/PathImpl.java#L435-L471","documentation":"If DocumentFile.createDirectory(lastSegment) returns null (the provider failed to create the directory), createDirectories() throws IOException(\"Directory<parentUri>/<lastSegment> could not be created.\"). Note the message has no space after \"Directory\" — a cosmetic bug. It signals the storage backend refused or failed the creation.","triggerScenarios":"file.createDirectory() returns null because the DocumentsProvider rejected the create: invalid characters in the name, name too long, read-only/external storage, or provider error.","commonSituations":"Writing to an SD card that is read-only or unmounted; directory names with characters the provider disallows; exhausted storage; SAF grants revoked so the tree is no longer writable.","solutions":["Verify the name contains only provider-safe characters (no slashes, control chars, or reserved names).","Check available storage and that the volume is writable/mounted before creating.","Re-acquire SAF permissions (ACTION_OPEN_DOCUMENT_TREE) and confirm canWrite() on the parent.","Retry against a different parent or use MediaStore/app-specific storage if SAF keeps failing."],"exampleFix":"// before\npath.createDirectories(dirName); // IOException: Directory...could not be created.\n// after\nDocumentFile parent = getRealDocumentFile(path);\nif (parent != null && parent.canWrite()) {\n    path.createDirectories(dirName);\n}","handlingStrategy":"try-catch","validationCode":"DocumentFile parent = getRealDocumentFile(path);\nboolean writable = parent != null && parent.canWrite() && parent.isDirectory();","typeGuard":null,"tryCatchPattern":"try {\n    return path.createDirectories(name);\n} catch (IOException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"could not be created\")) {\n        throw new IOException(\"Storage unwritable or name rejected: \" + name, e);\n    }\n    throw e;\n}","preventionTips":["Check canWrite() and storage space first","Keep SAF tree grants alive (persistable permissions)","Avoid provider-unsafe characters in names"],"tags":["android","saf","filesystem","directory-creation"],"backgroundTag":"file-write-failed","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}