{"record":{"id":"9a032359ad3882ac","repo":"MuntashirAkon/AppManager","slug":"path-cannot-be-opened-for-both-reading","errorCode":null,"errorMessage":"+ path + cannot be opened for both reading.","messagePattern":"\\+ path \\+ cannot be opened for both reading\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/io/fs/VirtualFileSystem.java","lineNumber":1009,"sourceCode":"    @NonNull\n    public FileChannel openChannel(String path, int mode) throws IOException {\n        boolean read = false;\n        boolean write = false;\n        if ((mode & MODE_READ_WRITE) != 0) {\n            read = true;\n            write = true;\n        } else if ((mode & MODE_READ_ONLY) != 0) {\n            read = true;\n        } else if ((mode & MODE_WRITE_ONLY) != 0) {\n            write = true;\n        } else {\n            throw new IllegalArgumentException(\"Bad mode: \" + mode);\n        }\n\n        if (read && write && !checkAccess(path, OsConstants.R_OK | OsConstants.W_OK)) {\n            throw new IOException(path + \" cannot be opened for both reading and writing.\");\n        } else if (read && !checkAccess(path, OsConstants.R_OK)) {\n            throw new IOException(path + \" cannot be opened for both reading.\");\n        } else if (write && !checkAccess(path, OsConstants.W_OK)) {\n            throw new IOException(path + \" cannot be opened for both writing.\");\n        }\n        Node<?> targetNode = getNode(path);\n        if (targetNode == null) {\n            throw new FileNotFoundException(path + \" does not exist.\");\n        }\n        if (!targetNode.isFile()) {\n            throw new IOException(path + \" is not a file.\");\n        }\n        return FileSystemManager.getLocal().openChannel(getCachedFile(targetNode, write), mode);\n    }\n\n    @NonNull\n    public ParcelFileDescriptor openFileDescriptor(String path, int mode) throws IOException {\n        boolean read = false;\n        boolean write = false;\n        if ((mode & MODE_READ_WRITE) != 0) {","sourceCodeStart":991,"sourceCodeEnd":1027,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/io/fs/VirtualFileSystem.java#L991-L1027","documentation":"VirtualFileSystem.openChannel(path, mode) throws this IOException when mode requires read and checkAccess(path, OsConstants.R_OK) fails — the path is not readable. Note the message string itself has a copy-paste bug (\"cannot be opened for both reading.\"), but the condition is the read-only branch of the access pre-flight.","triggerScenarios":"Calling openChannel with MODE_READ_ONLY (or MODE_READ_WRITE where the read check fails first... it does not — this branch is read-only) on a file the caller cannot read: restricted directory, permission bits, or a provider denying reads.","commonSituations":"Reading another app's private files without root; file with 0600 owned by a different UID; SELinux/AppArmor restriction on the backing path; broken provider authorization.","solutions":["Confirm the path is readable via checkAccess(path, R_OK) before opening","Request the needed host-OS permissions or use a provider/mount with read access","If root/privileged access is expected, verify the privileged mount is actually active","If the file should be writable, note you still need read permission for read-write mode"],"exampleFix":"// before\nFileChannel ch = vfs.openChannel(\"/data/data/other.app/db\", MODE_READ_ONLY); // no read access\n// after\nif (!vfs.checkAccess(path, OsConstants.R_OK)) {\n    requestAccessOrEscalate(path); // e.g. root/SAF flow\n}\nFileChannel ch = vfs.openChannel(path, MODE_READ_ONLY);","handlingStrategy":"try-catch","validationCode":"boolean readable = vfs.checkAccess(path, OsConstants.R_OK);","typeGuard":null,"tryCatchPattern":"try {\n    FileChannel ch = vfs.openChannel(path, MODE_READ_ONLY);\n} catch (IOException e) {\n    // trigger permission/privilege acquisition flow\n}","preventionTips":["Pre-flight R_OK before read opens","Note the misleading \"both reading\" message text — it still means a failed read-access check","Verify the privileged/root mount is active for protected paths"],"tags":["filesystem","virtual-fs","read-access"],"backgroundTag":"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"}