HMCL-dev/HMCL · error · FileNotFoundException
Source ' ' does not exist
Error message
Source '<srcFile>' does not exist
What it means
Guard in FileUtils.copyFile: the source path does not exist, so the copy cannot start. A FileNotFoundException naming the missing source is thrown before any I/O is attempted; generic pre-condition validation of the srcFile argument.
Solutions
- Verify the source path exists (Files.exists) and is spelled/resolved correctly before calling copyFile
- Use absolute paths or resolve against the correct base directory
- Recreate or re-download the missing source before copying
- Skip or log-and-continue when the source is legitimately absent
Example fix
// before
FileUtils.copyFile(new File("config.json").toPath(), backup);
// after
Path src = gameDir.resolve("config.json");
if (Files.exists(src)) FileUtils.copyFile(src, backup); Defensive patterns
Strategy: validation
Validate before calling
Path src = baseDir.resolve("file.dat").toAbsolutePath().normalize();
if (!Files.isRegularFile(src)) throw new FileNotFoundException(src.toString()); Type guard
static boolean isRegularFileOrNull(Path p) { return p != null && Files.isRegularFile(p); } Try / catch
try {
FileUtils.copyFile(src, dest);
} catch (FileNotFoundException e) {
// re-download/recreate the missing source
} Prevention
- Always resolve relative paths against an explicit base directory
- Check Files.exists/isRegularFile before copying
- Re-download sources that prior steps may have deleted
- Log the absolute path when configuring copy operations
When it happens
Trigger: Calling FileUtils.copyFile(srcFile, destFile) with a srcFile that was deleted, never created, or whose path is misspelled/relatively resolved.
Common situations: Copying mod profiles or game assets after a prior cleanup step removed them; wrong working directory making relative paths resolve elsewhere; race with another process deleting the file.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- Source ' ' exists but is a directory
- Destination ' ' exists but is read-only
- Asset index file malformed
- Bad exit code
- Cannot export a background directory as a theme-pack asset
AI-assisted analysis of HMCL-dev/HMCL@24702dc5a0 (2026-09-10).
Data as JSON: /api/errors/77648448487073c5.
Report an issue: GitHub.
Appendix: source
Thrown at HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/FileUtils.java:476
public static void copyFile(Path srcFile, Path destFile)
throws IOException {
Objects.requireNonNull(srcFile, "Source must not be null");
Objects.requireNonNull(destFile, "Destination must not be null");
if (!Files.exists(srcFile))
throw new FileNotFoundException("Source '" + srcFile + "' does not exist");
if (Files.isDirectory(srcFile))
throw new IOException("Source '" + srcFile + "' exists but is a directory");
Files.createDirectories(destFile.getParent());
if (Files.exists(destFile) && !Files.isWritable(destFile))
throw new IOException("Destination '" + destFile + "' exists but is read-only");
Files.copy(srcFile, destFile, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
}View on GitHub (pinned to 24702dc5a0)