{"record":{"id":"eca08f300159b1a9","repo":"asLody/VirtualApp","slug":"couldn-t-create","errorCode":null,"errorMessage":"Couldn't create ","messagePattern":"Couldn't create ","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"VirtualApp/lib/src/main/java/com/lody/virtual/helper/utils/AtomicFile.java","lineNumber":93,"sourceCode":"                    Log.w(\"AtomicFile\", \"Couldn't rename file \" + mBaseName\n                            + \" to backup file \" + mBackupName);\n                }\n            } else {\n                mBaseName.delete();\n            }\n        }\n        FileOutputStream str = null;\n        try {\n            str = new FileOutputStream(mBaseName);\n        } catch (FileNotFoundException e) {\n            File parent = mBaseName.getParentFile();\n            if (!parent.mkdir()) {\n                throw new IOException(\"Couldn't create directory \" + mBaseName);\n            }\n            try {\n                str = new FileOutputStream(mBaseName);\n            } catch (FileNotFoundException e2) {\n                throw new IOException(\"Couldn't create \" + mBaseName);\n            }\n        }\n        return str;\n    }\n\n    /**\n     * Call when you have successfully finished writing to the stream\n     * returned by {@link #startWrite()}.  This will close, sync, and\n     * commit the new data.  The next attempt to read the atomic file\n     * will return the new file stream.\n     */\n    public void finishWrite(FileOutputStream str) {\n        if (str != null) {\n            sync(str);\n            try {\n                str.close();\n                mBackupName.delete();\n            } catch (IOException e) {","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/asLody/VirtualApp/blob/666fefcb5d3f39cc944001c3457c38ffd6544c87/VirtualApp/lib/src/main/java/com/lody/virtual/helper/utils/AtomicFile.java#L75-L111","documentation":"After the initial open fails and the parent directory is successfully created, startWrite retries new FileOutputStream(mBaseName). If that second open also throws FileNotFoundException it throws this IOException 'Couldn't create <path>'. So the directory exists (or was just created) but the file itself cannot be created.","triggerScenarios":"Second FileOutputStream(mBaseName) attempt inside startWrite failing: permission denied on the file, a directory already exists at that path name, quota/disk-full, or SELinux policy blocking creation.","commonSituations":"Read-only filesystem; file owned by another uid after restore; disk full on /data; the base name collides with an existing directory.","solutions":["Check the path is not an existing directory and delete stale conflicting entries","Verify free disk space and file ownership/permissions of the target path","Catch IOException from startWrite and fall back to a writable cache dir location"],"exampleFix":"// before\nFile base = new File(\"/data/system/users/0/accounts.xml\"); // maybe a dir or read-only\n// after\nFile base = new File(context.getFilesDir(), \"accounts.xml\");\nif (base.isDirectory()) base.delete();\nAtomicFile af = new AtomicFile(base);","handlingStrategy":"try-catch","validationCode":"if (base.isDirectory() || (base.exists() && !base.canWrite())) {\n    throw new IOException(\"bad target: \" + base);\n}","typeGuard":null,"tryCatchPattern":"try {\n    FileOutputStream out = atomicFile.startWrite();\n} catch (IOException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Couldn't create \")) {\n        // free disk space / fix permissions / fall back to alternate path\n    }\n}","preventionTips":["Check free disk space before large atomic writes","Avoid name collisions between files and directories","Handle Android storage permissions/scoped storage"],"tags":["android","io","file-write","atomic-file"],"backgroundTag":"file-write-failed","analyzedSha":"666fefcb5d3f39cc944001c3457c38ffd6544c87","analyzedAt":"2026-09-09T11:09:01.694Z","contentChangedAt":"2026-09-09T11:09:01.694Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}