lingochamp/FileDownloader · error · RuntimeException
found invalid internal destination path, empty
Error message
found invalid internal destination path, empty
What it means
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.
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.
Example fix
// before
FileDownloadUtils.createOutputStream(task.getPath()); // ""
// after
String path = task.getPath();
if (path == null || path.isEmpty()) {
path = FileDownloadUtils.getDefaultSaveDirectory() + File.separator + "download.bin";
}
FileDownloadUtils.createOutputStream(path); Defensive patterns
Strategy: validation
Validate before calling
String path = task.getPath();
if (path == null || path.trim().isEmpty()) {
path = FileDownloadUtils.getDefaultSaveDirectory() + File.separator + "download.bin";
} Type guard
boolean isValidPath(String p) { return p != null && !p.trim().isEmpty(); } Try / catch
try {
stream = FileDownloadUtils.createOutputStream(path);
} catch (RuntimeException e) {
// path unresolved: fix task path or use default before retrying
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- found invalid internal destination filename
- fetched length[ ] != content length[ ], range[ , ) offset[…
- listener must not be null!
- event must not be null!
- can't create the block complete message for id
AI-assisted analysis of lingochamp/FileDownloader@6237a8cac1 (2026-09-08).
Data as JSON: /api/errors/e632b4720acce5f2.
Report an issue: GitHub.
Appendix: source
Thrown at library/src/main/java/com/liulishuo/filedownloader/util/FileDownloadUtils.java:684
}
if (TextUtils.isEmpty(filename)) {
filename = FileDownloadUtils.generateFileName(url);
} else if (filename.contains("../")) {
throw new FileDownloadSecurityException(FileDownloadUtils.formatString(
"The filename [%s] from the response is not allowable, because it contains "
+ "'../', which can raise the directory traversal vulnerability",
filename));
}
return filename;
}
public static FileDownloadOutputStream createOutputStream(final String path)
throws IOException {
if (TextUtils.isEmpty(path)) {
throw new RuntimeException("found invalid internal destination path, empty");
}
//noinspection ConstantConditions
if (!FileDownloadUtils.isFilenameValid(path)) {
throw new RuntimeException(
FileDownloadUtils.formatString("found invalid internal destination filename"
+ " %s", path));
}
File file = new File(path);
if (file.exists() && file.isDirectory()) {
throw new RuntimeException(
FileDownloadUtils.formatString("found invalid internal destination path[%s],"
+ " & path is directory[%B]", path, file.isDirectory()));
}
if (!file.exists()) {
if (!file.createNewFile()) {View on GitHub (pinned to 6237a8cac1)