{"record":{"id":"e632b4720acce5f2","repo":"lingochamp/FileDownloader","slug":"found-invalid-internal-destination-path-empty","errorCode":null,"errorMessage":"found invalid internal destination path, empty","messagePattern":"found invalid internal destination path, empty","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/liulishuo/filedownloader/util/FileDownloadUtils.java","lineNumber":684,"sourceCode":"        }\n\n        if (TextUtils.isEmpty(filename)) {\n            filename = FileDownloadUtils.generateFileName(url);\n        } else if (filename.contains(\"../\")) {\n            throw new FileDownloadSecurityException(FileDownloadUtils.formatString(\n                    \"The filename [%s] from the response is not allowable, because it contains \"\n                            + \"'../', which can raise the directory traversal vulnerability\",\n                    filename));\n        }\n\n        return filename;\n    }\n\n    public static FileDownloadOutputStream createOutputStream(final String path)\n            throws IOException {\n\n        if (TextUtils.isEmpty(path)) {\n            throw new RuntimeException(\"found invalid internal destination path, empty\");\n        }\n\n        //noinspection ConstantConditions\n        if (!FileDownloadUtils.isFilenameValid(path)) {\n            throw new RuntimeException(\n                    FileDownloadUtils.formatString(\"found invalid internal destination filename\"\n                            + \" %s\", path));\n        }\n\n        File file = new File(path);\n\n        if (file.exists() && file.isDirectory()) {\n            throw new RuntimeException(\n                    FileDownloadUtils.formatString(\"found invalid internal destination path[%s],\"\n                            + \" & path is directory[%B]\", path, file.isDirectory()));\n        }\n        if (!file.exists()) {\n            if (!file.createNewFile()) {","sourceCodeStart":666,"sourceCodeEnd":702,"githubUrl":"https://github.com/lingochamp/FileDownloader/blob/6237a8cac174bcc916e4342b14ab1ab72a5768d4/library/src/main/java/com/liulishuo/filedownloader/util/FileDownloadUtils.java#L666-L702","documentation":"createOutputStream opens the output stream for writing downloaded data to the destination path. An empty path is an internal invariant violation (the library always computes a concrete path before writing), so it throws RuntimeException instead of attempting to create a file at an invalid location.","triggerScenarios":"FileDownloadUtils.createOutputStream(\"\") or createOutputStream(null), i.e. the task's target file path resolved to empty — typically a task created without a path where filename generation also failed.","commonSituations":"Tasks started without setPath and with null server-derived filename; custom code invoking createOutputStream directly with an unset path variable; path wiped by a later reassignment.","solutions":["Set an explicit target path on the task: task.setPath(absolutePath) before enqueueing.","Verify the resolved path (FileDownloadUtils.getTargetFilePath) is non-empty before starting the download.","If calling createOutputStream directly, validate with TextUtils.isEmpty(path) first and fail with a descriptive error."],"exampleFix":"// before\nFileDownloadUtils.createOutputStream(task.getPath()); // \"\"\n\n// after\nString path = task.getPath();\nif (path == null || path.isEmpty()) {\n    path = FileDownloadUtils.getDefaultSaveDirectory() + File.separator + \"download.bin\";\n}\nFileDownloadUtils.createOutputStream(path);","handlingStrategy":"validation","validationCode":"String path = task.getPath();\nif (path == null || path.trim().isEmpty()) {\n    path = FileDownloadUtils.getDefaultSaveDirectory() + File.separator + \"download.bin\";\n}","typeGuard":"boolean isValidPath(String p) { return p != null && !p.trim().isEmpty(); }","tryCatchPattern":"try {\n    stream = FileDownloadUtils.createOutputStream(path);\n} catch (RuntimeException e) {\n    // path unresolved: fix task path or use default before retrying\n}","preventionTips":["Always call task.setPath(...) with an absolute path before enqueueing.","Assert the resolved target path is non-empty in debug builds before starting downloads.","Centralize path resolution so a failed filename derivation cannot yield an empty string."],"tags":["android","file-io","empty-path","filedownloader"],"backgroundTag":"empty-required-field","analyzedSha":"6237a8cac174bcc916e4342b14ab1ab72a5768d4","analyzedAt":"2026-09-08T23:50:48.168Z","contentChangedAt":"2026-09-08T23:50:48.168Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}