{"record":{"id":"74fbe702a1d82f09","repo":"lingochamp/FileDownloader","slug":"the-provided-mpath-s-is-invalid-can-t-find-its","errorCode":null,"errorMessage":"the provided mPath[%s] is invalid, can't find its directory","messagePattern":"the provided mPath\\[(.+?)\\] is invalid, can't find its directory","errorType":"validation","errorClass":"InvalidParameterException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/liulishuo/filedownloader/DownloadTaskHunter.java","lineNumber":543,"sourceCode":"\n    private void prepare() throws IOException {\n        final BaseDownloadTask.IRunningTask runningTask = mTask.getRunningTask();\n        final BaseDownloadTask origin = runningTask.getOrigin();\n\n        if (origin.getPath() == null) {\n            origin.setPath(FileDownloadUtils.getDefaultSaveFilePath(origin.getUrl()));\n            if (FileDownloadLog.NEED_LOG) {\n                FileDownloadLog.d(this, \"save Path is null to %s\", origin.getPath());\n            }\n        }\n\n        final File dir;\n        if (origin.isPathAsDirectory()) {\n            dir = new File(origin.getPath());\n        } else {\n            final String dirString = FileDownloadUtils.getParent(origin.getPath());\n            if (dirString == null) {\n                throw new InvalidParameterException(\n                        FileDownloadUtils.formatString(\"the provided mPath[%s] is invalid,\"\n                                + \" can't find its directory\", origin.getPath()));\n            }\n            dir = new File(dirString);\n        }\n\n        if (!dir.exists()) {\n            if (!dir.mkdirs() && !dir.exists()) {\n                throw new IOException(FileDownloadUtils.\n                        formatString(\"Create parent directory failed, please make sure \"\n                                        + \"you have permission to create file or directory \"\n                                        + \"on the path: %s\",\n                                dir.getAbsolutePath()));\n            }\n        }\n    }\n\n    private int getId() {","sourceCodeStart":525,"sourceCodeEnd":561,"githubUrl":"https://github.com/lingochamp/FileDownloader/blob/6237a8cac174bcc916e4342b14ab1ab72a5768d4/library/src/main/java/com/liulishuo/filedownloader/DownloadTaskHunter.java#L525-L561","documentation":"DownloadTaskHunter.prepare() throws InvalidParameterException when the task's target file path has no derivable parent directory (FileDownloadUtils.getParent returns null). The library must know which directory to create/manage the file in before downloading.","triggerScenarios":"Passing a path with no directory component or a malformed path (e.g. empty string, null-ish path) to FileDownloader.create(url, path) where path is not itself a directory.","commonSituations":"Programmatically built paths from concatenation producing \"\" or \"/file\"-style paths; paths with invalid characters on the device filesystem.","solutions":["Provide an absolute path including a valid directory, e.g. \"/sdcard/download/file.zip\".","Use FileDownloaderUtils or File(path, name) style construction to guarantee a parent directory.","Validate the path with FileDownloadUtils.getParent(path) != null before creating the task."],"exampleFix":"// before\nFileDownloader.getImpl().create(url, \"\");\n\n// after\nFile file = new File(context.getExternalFilesDir(null), \"file.zip\");\nFileDownloader.getImpl().create(url, file.getAbsolutePath());","handlingStrategy":"validation","validationCode":"String dir = FileDownloadUtils.getParent(path);\nif (dir == null) throw new IllegalArgumentException(\"path needs a valid parent directory: \" + path);","typeGuard":"boolean hasValidParent(String p) { return p != null && FileDownloadUtils.getParent(p) != null; }","tryCatchPattern":null,"preventionTips":["Always build paths from a real directory plus file name.","Use context.getExternalFilesDir(null) rather than string concatenation.","Validate paths in a task-factory helper."],"tags":["android","file-path","validation"],"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"}