{"record":{"id":"6509af18d4f07a05","repo":"MuntashirAkon/AppManager","slug":"read-append-not-allowed","errorCode":null,"errorMessage":"READ + APPEND not allowed","messagePattern":"READ \\+ APPEND not allowed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"libcore/io/src/main/java/io/github/muntashirakon/io/FileUtils.java","lineNumber":129,"sourceCode":"            f.write = true;\n        } else if ((mode & MODE_READ_ONLY) == MODE_READ_ONLY) {\n            f.read = true;\n        } else {\n            throw new IllegalArgumentException(\"Bad mode: \" + mode);\n        }\n        if ((mode & MODE_CREATE) == MODE_CREATE) {\n            f.create = true;\n        }\n        if ((mode & MODE_TRUNCATE) == MODE_TRUNCATE) {\n            f.truncate = true;\n        }\n        if ((mode & MODE_APPEND) == MODE_APPEND) {\n            f.append = true;\n        }\n\n        // Validate flags\n        if (f.append && f.read) {\n            throw new IllegalArgumentException(\"READ + APPEND not allowed\");\n        }\n        if (f.append && f.truncate) {\n            throw new IllegalArgumentException(\"APPEND + TRUNCATE not allowed\");\n        }\n\n        return f;\n    }\n\n    @RequiresApi(api = 28)\n    static long splice(\n            FileDescriptor fdIn, Int64Ref offIn,\n            FileDescriptor fdOut, Int64Ref offOut,\n            long len, int flags) throws ErrnoException {\n        try {\n            if (splice == null) {\n                splice = Os.class.getMethod(\"splice\",\n                        FileDescriptor.class, Int64Ref.class,\n                        FileDescriptor.class, Int64Ref.class,","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/libcore/io/src/main/java/io/github/muntashirakon/io/FileUtils.java#L111-L147","documentation":"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\").","triggerScenarios":"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.","commonSituations":"Translating C open() modes like \"a+\" (read+append) directly into flags without realizing this library forbids it; combining convenience flags from different APIs.","solutions":["Remove MODE_APPEND when read access is needed; open MODE_READ_WRITE and seek/write manually instead.","Choose append-only (MODE_APPEND | MODE_WRITE_ONLY) if you only add data to the end.","Validate before calling: ((mode & MODE_APPEND) != 0 && (mode & (MODE_READ_ONLY|MODE_READ_WRITE)) != 0) is invalid."],"exampleFix":"// before\nint mode = MODE_APPEND | MODE_READ_WRITE; // throws\n// after\nint mode = MODE_READ_WRITE; // then seek to end before writing","handlingStrategy":"validation","validationCode":"if ((mode & FileSystemManager.MODE_APPEND) != 0 &&\n    (mode & (FileSystemManager.MODE_READ_ONLY | FileSystemManager.MODE_READ_WRITE)) != 0) {\n    mode &= ~FileSystemManager.MODE_APPEND; // or reject\n}","typeGuard":null,"tryCatchPattern":"try {\n    fs.openFile(f, mode);\n} catch (IllegalArgumentException e) {\n    if (\"READ + APPEND not allowed\".equals(e.getMessage())) {\n        mode = FileSystemManager.MODE_READ_WRITE; // open read-write and seek\n    }\n}","preventionTips":["Never combine MODE_APPEND with read access","Map 'a+' style modes to MODE_READ_WRITE + seek","Keep append usage to MODE_APPEND | MODE_WRITE_ONLY"],"tags":["io","file-mode","conflicting-flags"],"backgroundTag":"mutually-exclusive-flags","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}