{"record":{"id":"9dfa843130efa254","repo":"lingochamp/FileDownloader","slug":"found-invalid-internal-destination-path-s-pat","errorCode":null,"errorMessage":"found invalid internal destination path[%s], & path is directory[%B]","messagePattern":"found invalid internal destination path\\[(.+?)\\], & path is directory\\[%B\\]","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/liulishuo/filedownloader/util/FileDownloadUtils.java","lineNumber":697,"sourceCode":"\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()) {\n                throw new IOException(\n                        FileDownloadUtils.formatString(\"create new file error  %s\",\n                                file.getAbsolutePath()));\n            }\n        }\n\n        return CustomComponentHolder.getImpl().createOutputStream(file);\n    }\n\n    public static boolean isBreakpointAvailable(final int id, final FileDownloadModel model) {\n        return isBreakpointAvailable(id, model, null);\n    }\n","sourceCodeStart":679,"sourceCodeEnd":715,"githubUrl":"https://github.com/lingochamp/FileDownloader/blob/6237a8cac174bcc916e4342b14ab1ab72a5768d4/library/src/main/java/com/liulishuo/filedownloader/util/FileDownloadUtils.java#L679-L715","documentation":"FileDownloadUtils.createOutputStream throws this RuntimeException when the target download path already exists and is a directory instead of a regular file. The library requires the destination path to be a creatable/writable file, so it aborts with a formatted message showing the path and the isDirectory flag.","triggerScenarios":"Calling download APIs (e.g. FileDownloader.get(...).create() or start()) whose computed destination path (via FileDownloadUtils.generateFilePath or a custom path passed to FileDownloadRequest/setPath) resolves to an existing directory, or a path whose filename component is empty so the path is a directory.","commonSituations":"Developers set a custom download path ending in '/' or omitting a filename, point two downloads at the same directory path, or reuse a path previously created via mkdir(). Storage-mount changes (SD card swapped) can also leave a directory where a file was expected.","solutions":["Print the computed path with FileDownloadUtils.generateFilePath(id) and confirm it ends in a file name, not a directory.","Remove the existing directory at that path (or pick a different destination path) before retrying the download.","If supplying a custom path, ensure you pass a full file path (e.g. /sdcard/Download/myfile.apk), not a directory.","Check that no other code in the app creates a directory at the same path used as the download destination."],"exampleFix":"// before\nrequest.setPath(Environment.getExternalStorageDirectory() + \"/Download/\");\n// after\nFile dest = new File(context.getExternalFilesDir(null), \"myfile.apk\");\nif (dest.isDirectory()) {\n    dest.delete();\n}\nrequest.setPath(dest.getAbsolutePath());","handlingStrategy":"validation","validationCode":"File dest = new File(path);\nif (dest.exists() && dest.isDirectory()) {\n    dest.delete(); // or choose another path\n}","typeGuard":null,"tryCatchPattern":"try {\n    downloader.create(path);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"invalid internal destination path\")) {\n        new File(path).delete();\n        // retry or pick alternate path\n    }\n}","preventionTips":["Always pass full file paths (with filename), never directories.","Use FileDownloadUtils.generateFilePath(id) to compute destinations.","Sanitize user-supplied filenames to avoid empty names or trailing slashes.","Log and verify the destination path before starting downloads."],"tags":["file","io","path","filedownloader"],"backgroundTag":"invalid-argument-value","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"}