MuntashirAkon/AppManager · error

APPEND + TRUNCATE not allowed

Error message

APPEND + TRUNCATE not allowed

What it means

This library's FileUtils.modeToFlag() converts a POSIX-style mode string (e.g. "rw", "rwt") into a Flag object and validates flag combinations. APPEND combined with TRUNCATE is rejected because truncating the file on open contradicts appending to its end — the kernel's O_APPEND|O_TRUNC combination would erase data the caller apparently intended to keep. The library fails fast with IllegalArgumentException rather than producing surprising file contents.

Source

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

        } 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,
                        long.class, int.class);
            }
            return (long) splice.invoke(null, fdIn, offIn, fdOut, offOut, len, flags);

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Remove the truncate flag from the mode string (use "a" alone to append, or "wt"/"w" alone to truncate then write)
  2. If truncate-then-append is truly wanted, open with "wt", write, then reopen with "a"
  3. Validate mode strings before passing them, rejecting any mode that implies both append and truncate

Example fix

// before
FileUtils.modeToFlag("wat"); // IllegalArgumentException: APPEND + TRUNCATE not allowed
// after
FileUtils.modeToFlag("wa"); // append-only, or "wt" to truncate then write
Defensive patterns

Strategy: validation

Validate before calling

FileUtils.Flag f = FileUtils.modeToFlag(mode); // or pre-check the mode string
if (mode.contains("a") && mode.contains("t")) throw new IllegalArgumentException("mode must not combine append and truncate");

Type guard

boolean isConflictingMode(String mode) { return mode != null && mode.contains("a") && mode.contains("t"); }

Try / catch

try { FileUtils.modeToFlag(mode); } catch (IllegalArgumentException e) { /* fix mode string or prompt user */ }

Prevention

When it happens

Trigger: Calling FileUtils.modeToFlag() (directly or via NIOFactory.openChannel / FileSystemManager openers) with a mode string that parses to both append and truncate, e.g. "ra", "wa", or a mode containing both 'a' and 't' semantics.

Common situations: Constructing mode strings programmatically by concatenating flags; porting code that used "wa" assuming truncate-then-append; users specifying custom open modes in remote file-system calls.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


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