MuntashirAkon/AppManager · error · IOException

+ path + cannot be opened for both writing.

Error message

+ path + cannot be opened for both writing.

What it means

VirtualFileSystem.openChannel(path, mode) throws this IOException when mode requires write and checkAccess(path, OsConstants.W_OK) fails — the path is not writable. (The message string has a copy-paste bug saying "both writing"; the condition is the write-only branch.)

Source

Thrown at app/src/main/java/io/github/muntashirakon/io/fs/VirtualFileSystem.java:1011

        boolean read = false;
        boolean write = false;
        if ((mode & MODE_READ_WRITE) != 0) {
            read = true;
            write = true;
        } else if ((mode & MODE_READ_ONLY) != 0) {
            read = true;
        } else if ((mode & MODE_WRITE_ONLY) != 0) {
            write = true;
        } else {
            throw new IllegalArgumentException("Bad mode: " + mode);
        }

        if (read && write && !checkAccess(path, OsConstants.R_OK | OsConstants.W_OK)) {
            throw new IOException(path + " cannot be opened for both reading and writing.");
        } else if (read && !checkAccess(path, OsConstants.R_OK)) {
            throw new IOException(path + " cannot be opened for both reading.");
        } else if (write && !checkAccess(path, OsConstants.W_OK)) {
            throw new IOException(path + " cannot be opened for both writing.");
        }
        Node<?> targetNode = getNode(path);
        if (targetNode == null) {
            throw new FileNotFoundException(path + " does not exist.");
        }
        if (!targetNode.isFile()) {
            throw new IOException(path + " is not a file.");
        }
        return FileSystemManager.getLocal().openChannel(getCachedFile(targetNode, write), mode);
    }

    @NonNull
    public ParcelFileDescriptor openFileDescriptor(String path, int mode) throws IOException {
        boolean read = false;
        boolean write = false;
        if ((mode & MODE_READ_WRITE) != 0) {
            read = true;
            write = true;

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Check checkAccess(path, W_OK) before opening and fall back to a writable copy
  2. Mount the source with write support or use a privileged/root mount if intended
  3. Request host-OS write permissions
  4. If only reading is needed, switch to MODE_READ_ONLY

Example fix

// before
FileChannel ch = vfs.openChannel("/system/etc/hosts", MODE_WRITE_ONLY); // read-only
// after
FileChannel ch = vfs.checkAccess(path, OsConstants.W_OK)
    ? vfs.openChannel(path, MODE_WRITE_ONLY)
    : vfs.openChannel(copyToWritable(path), MODE_WRITE_ONLY);
Defensive patterns

Strategy: try-catch

Validate before calling

boolean writable = vfs.checkAccess(path, OsConstants.W_OK);

Try / catch

try {
    FileChannel ch = vfs.openChannel(path, MODE_WRITE_ONLY);
} catch (IOException e) {
    // fall back to a writable copy or surface read-only UI state
}

Prevention

When it happens

Trigger: openChannel with MODE_WRITE_ONLY or MODE_READ_WRITE (write check) on a read-only mount, a file without write permission bits, or a location the current process cannot modify.

Common situations: Patching files on /system or a read-only SAF grant; editing another app's data without root; disk-full or error-remounted read-only filesystem.

Understand the failure class

Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/8fd792a8feebfbe9. Report an issue: GitHub.