{"record":{"id":"e835154ffff43d38","repo":"TeamNewPipe/NewPipe","slug":"cannot-create-a-temporal-file","errorCode":null,"errorMessage":"Cannot create a temporal file","messagePattern":"Cannot create a temporal file","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/us/shandian/giga/io/CircularFileWriter.java","lineNumber":35,"sourceCode":"    private static final int THRESHOLD_AUX_LENGTH = 15 * 1024 * 1024;// 15 MiB\n\n    private final OffsetChecker callback;\n\n    public ProgressReport onProgress;\n    public WriteErrorHandle onWriteError;\n\n    private long reportPosition;\n    private long maxLengthKnown = -1;\n\n    private BufferedFile out;\n    private BufferedFile aux;\n\n    public CircularFileWriter(SharpStream target, File temp, OffsetChecker checker) throws IOException {\n        Objects.requireNonNull(checker);\n\n        if (!temp.exists()) {\n            if (!temp.createNewFile()) {\n                throw new IOException(\"Cannot create a temporal file\");\n            }\n        }\n\n        aux = new BufferedFile(temp);\n        out = new BufferedFile(target);\n\n        callback = checker;\n\n        reportPosition = NOTIFY_BYTES_INTERVAL;\n    }\n\n    private void flushAuxiliar(long amount) throws IOException {\n        if (aux.length < 1) {\n            return;\n        }\n\n        out.flush();\n        aux.flush();","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/TeamNewPipe/NewPipe/blob/9e8be091560a69f35d44bd252eb00bc7911c977b/app/src/main/java/us/shandian/giga/io/CircularFileWriter.java#L17-L53","documentation":"Thrown by CircularFileWriter's constructor when the auxiliary temp File does not exist and createNewFile() returns false. CircularFileWriter uses a secondary temp file as a circular buffer for download data; if it cannot create that temp file (path unwritable, parent missing, permission denied), the writer cannot operate and throws. Note: if the temp file already exists, this check is skipped.","triggerScenarios":"new CircularFileWriter(target, temp, checker) where !temp.exists() && !temp.createNewFile(). createNewFile returns false when the parent directory does not exist, is read-only, or the process lacks write permission at that path.","commonSituations":"Download temp directory was deleted or is on unmounted storage; app lost write permission to the chosen path; the temp path's parent was never created (mkdirs not called); disk full so createNewFile fails; path points to a file:// location on read-only external storage.","solutions":["Ensure the parent directory of 'temp' exists and is writable (call temp.getParentFile().mkdirs()) before constructing the writer.","Verify write permission and available space on the target volume before starting the download.","Use context.getCacheDir() or getExternalCacheDir() for temp files, which are always writable by the app.","Catch IOException and retry with a fallback temp location."],"exampleFix":"// before\nnew CircularFileWriter(target, tempFile, checker);\n\n// after — guarantee parent dir exists\nFile parent = tempFile.getParentFile();\nif (parent != null && !parent.exists() && !parent.mkdirs()) {\n    throw new IOException(\"Cannot create temp parent dir: \" + parent);\n}\nnew CircularFileWriter(target, tempFile, checker);","handlingStrategy":"validation","validationCode":"// Ensure temp file parent exists before constructing the writer:\nFile parent = temp.getParentFile();\nif (parent != null && !parent.exists() && !parent.mkdirs()) {\n    throw new IOException(\"Cannot create temp parent dir: \" + parent);\n}","typeGuard":null,"tryCatchPattern":"try {\n    CircularFileWriter writer = new CircularFileWriter(target, temp, checker);\n} catch (IOException e) {\n    if (\"Cannot create a temporal file\".equals(e.getMessage())) {\n        // retry with a cache-dir temp location\n        temp = new File(context.getCacheDir(), temp.getName());\n        writer = new CircularFileWriter(target, temp, checker);\n    } else throw e;\n}","preventionTips":["Use context.getCacheDir() for temp files — always writable by the app.","Call mkdirs() on the temp file's parent directory before creating it.","Check available disk space before starting a download that needs a temp buffer."],"tags":["io","download","temp-file","storage","file-creation"],"backgroundTag":null,"analyzedSha":"9e8be091560a69f35d44bd252eb00bc7911c977b","analyzedAt":"2026-08-14T00:11:33.519Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}