HMCL-dev/HMCL · error · IllegalArgumentException

"File '" + file + "' is not a resource pack"

Error message

"File '" + file + "' is not a resource pack"

What it means

ResourcePackManager.importResourcePack only accepts files that pass its resource-pack detection (valid pack archive with pack metadata). When the given file fails detection, it throws IllegalArgumentException indicating the file is not a resource pack. This is a caller input validation error inside the import flow, thrown while holding the manager lock.

Solutions

  1. Confirm the file is a zip/jar resource pack containing pack.mcmeta at its root
  2. Only pass recognized resource pack files to importResourcePack; use the mod manager for mods
  3. Re-download or rebuild the pack if the archive is corrupt

Example fix

// before
rpm.importResourcePack(Path.of("sodium.jar")); // a mod, not a pack
// after
Path pack = Path.of("~/Downloads/Faithful-32x.zip");
if (ResourcePackManager.isResourcePackFile(pack)) {
    rpm.importResourcePack(pack);
}
Defensive patterns

Strategy: validation

Validate before calling

if (!ResourcePackManager.isResourcePackFile(file)) {
    return; // or show user error
}
resourcePackManager.importResourcePack(file);

Type guard

boolean looksLikePack = file.getFileName().toString().toLowerCase().matches(".*\\.(zip|jar)");

Try / catch

try {
    resourcePackManager.importResourcePack(file);
} catch (IllegalArgumentException e) {
    ui.showWarning("Selected file is not a resource pack");
}

Prevention

When it happens

Trigger: Calling importResourcePack(Path file) with a file whose content/structure does not validate as a resource pack (e.g. a plain jar without pack.mcmeta, a corrupt zip, or a directory).

Common situations: Importing a mod jar or shader pack by mistake into the resource-pack manager; importing a texture folder that was never zipped with pack.mcmeta; downloading a truncated archive.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


AI-assisted analysis of HMCL-dev/HMCL@24702dc5a0 (2026-09-10). Data as JSON: /api/errors/9d1800428290772f. Report an issue: GitHub.

Appendix: source

Thrown at HMCLCore/src/main/java/org/jackhuang/hmcl/addon/resourcepack/ResourcePackManager.java:375

    public void importResourcePack(Path file) throws IOException, IllegalArgumentException {
        lock.lock();
        try {
            if (ResourcePackFile.isFileResourcePack(file)) {
                if (!loaded)
                    refresh();
                Files.createDirectories(resourcePackDirectory);

                Path newFile = resourcePackDirectory.resolve(file.getFileName());
                if (Files.isDirectory(file)) {
                    FileUtils.copyDirectory(file, newFile);
                } else {
                    FileUtils.copyFile(file, newFile);
                }

                addResourcePackInfo(newFile);
            } else {
                throw new IllegalArgumentException("File '" + file + "' is not a resource pack");
            }
        } finally {
            lock.unlock();
        }
    }

    public boolean removeResourcePacks(List<ResourcePackFile> resourcePacks) throws IOException {
        lock.lock();
        try {
            boolean modified = disableResourcePacks(resourcePacks);
            for (ResourcePackFile resourcePack : resourcePacks) {
                if (resourcePack != null && resourcePack.manager == this) {
                    resourcePack.delete();
                    localFiles.remove(resourcePack);
                    modified = true;
                }
            }
            return modified;

View on GitHub (pinned to 24702dc5a0)