MuntashirAkon/AppManager · error

READ + APPEND not allowed

Error message

READ + APPEND not allowed

What it means

modeToFlag() rejects semantically conflicting combinations after decoding bits: append mode implies write-only positioning at end-of-file, so combining MODE_APPEND with a read bit is invalid. It throws IllegalArgumentException("READ + APPEND not allowed").

Solutions

  1. Remove MODE_APPEND when read access is needed; open MODE_READ_WRITE and seek/write manually instead.
  2. Choose append-only (MODE_APPEND | MODE_WRITE_ONLY) if you only add data to the end.
  3. Validate before calling: ((mode & MODE_APPEND) != 0 && (mode & (MODE_READ_ONLY|MODE_READ_WRITE)) != 0) is invalid.

Example fix

// before
int mode = MODE_APPEND | MODE_READ_WRITE; // throws
// after
int mode = MODE_READ_WRITE; // then seek to end before writing
Defensive patterns

Strategy: validation

Validate before calling

if ((mode & FileSystemManager.MODE_APPEND) != 0 &&
    (mode & (FileSystemManager.MODE_READ_ONLY | FileSystemManager.MODE_READ_WRITE)) != 0) {
    mode &= ~FileSystemManager.MODE_APPEND; // or reject
}

Try / catch

try {
    fs.openFile(f, mode);
} catch (IllegalArgumentException e) {
    if ("READ + APPEND not allowed".equals(e.getMessage())) {
        mode = FileSystemManager.MODE_READ_WRITE; // open read-write and seek
    }
}

Prevention

When it happens

Trigger: Passing mode = MODE_APPEND | MODE_READ_ONLY or MODE_APPEND | MODE_READ_WRITE — any mode where both the append bit and a read bit are set.

Common situations: Translating C open() modes like "a+" (read+append) directly into flags without realizing this library forbids it; combining convenience flags from different APIs.

Understand the failure class

Background: "mutually exclusive" flag errors: what "can't supply both nx and xx", "--raw is not compatible with -i" and "cannot be used with" mean, and how to fix them — this error's family across 29 libraries.

Related errors


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

Appendix: source

Thrown at libcore/io/src/main/java/io/github/muntashirakon/io/FileUtils.java:129

            f.write = true;
        } else if ((mode & MODE_READ_ONLY) == MODE_READ_ONLY) {
            f.read = true;
        } else {
            throw new IllegalArgumentException("Bad mode: " + mode);
        }
        if ((mode & MODE_CREATE) == MODE_CREATE) {
            f.create = true;
        }
        if ((mode & MODE_TRUNCATE) == MODE_TRUNCATE) {
            f.truncate = true;
        }
        if ((mode & MODE_APPEND) == MODE_APPEND) {
            f.append = true;
        }

        // Validate flags
        if (f.append && f.read) {
            throw new IllegalArgumentException("READ + APPEND not allowed");
        }
        if (f.append && f.truncate) {
            throw new IllegalArgumentException("APPEND + TRUNCATE not allowed");
        }

        return f;
    }

    @RequiresApi(api = 28)
    static long splice(
            FileDescriptor fdIn, Int64Ref offIn,
            FileDescriptor fdOut, Int64Ref offOut,
            long len, int flags) throws ErrnoException {
        try {
            if (splice == null) {
                splice = Os.class.getMethod("splice",
                        FileDescriptor.class, Int64Ref.class,
                        FileDescriptor.class, Int64Ref.class,

View on GitHub (pinned to 0152f468fc)