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

  1. Verify the source path exists (Files.exists) and is spelled/resolved correctly before calling copyFile
  2. Use absolute paths or resolve against the correct base directory
  3. Recreate or re-download the missing source before copying
  4. 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

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


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)