lingochamp/FileDownloader · error · InvalidParameterException
the provided mPath[ ] is invalid, can't find its directory
Error message
the provided mPath[%s] is invalid, can't find its directory
What it means
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.
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.
Example fix
// before FileDownloader.getImpl().create(url, ""); // after File file = new File(context.getExternalFilesDir(null), "file.zip"); FileDownloader.getImpl().create(url, file.getAbsolutePath());
Defensive patterns
Strategy: validation
Validate before calling
String dir = FileDownloadUtils.getParent(path);
if (dir == null) throw new IllegalArgumentException("path needs a valid parent directory: " + path); Type guard
boolean hasValidParent(String p) { return p != null && FileDownloadUtils.getParent(p) != null; } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Programmatically built paths from concatenation producing "" or "/file"-style paths; paths with invalid characters on the device filesystem.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- If you start the task manually, it means this task doesn't…
- This task is running
- This task is dirty to restart, If you want to reuse this…
- Create parent directory failed, please make sure you have…
- Sorry, FileDownloader can not block the main thread…
AI-assisted analysis of lingochamp/FileDownloader@6237a8cac1 (2026-09-08).
Data as JSON: /api/errors/74fbe702a1d82f09.
Report an issue: GitHub.
Appendix: source
Thrown at library/src/main/java/com/liulishuo/filedownloader/DownloadTaskHunter.java:543
private void prepare() throws IOException {
final BaseDownloadTask.IRunningTask runningTask = mTask.getRunningTask();
final BaseDownloadTask origin = runningTask.getOrigin();
if (origin.getPath() == null) {
origin.setPath(FileDownloadUtils.getDefaultSaveFilePath(origin.getUrl()));
if (FileDownloadLog.NEED_LOG) {
FileDownloadLog.d(this, "save Path is null to %s", origin.getPath());
}
}
final File dir;
if (origin.isPathAsDirectory()) {
dir = new File(origin.getPath());
} else {
final String dirString = FileDownloadUtils.getParent(origin.getPath());
if (dirString == null) {
throw new InvalidParameterException(
FileDownloadUtils.formatString("the provided mPath[%s] is invalid,"
+ " can't find its directory", origin.getPath()));
}
dir = new File(dirString);
}
if (!dir.exists()) {
if (!dir.mkdirs() && !dir.exists()) {
throw new IOException(FileDownloadUtils.
formatString("Create parent directory failed, please make sure "
+ "you have permission to create file or directory "
+ "on the path: %s",
dir.getAbsolutePath()));
}
}
}
private int getId() {View on GitHub (pinned to 6237a8cac1)