HMCL-dev/HMCL · error · IllegalArgumentException

Theme-pack resource name is blank

Error message

Theme-pack resource name is blank

What it means

The ThemePackResource.File compact constructor normalizes the path and trims the name; if the trimmed resource name is empty it throws IllegalArgumentException "Theme-pack resource name is blank". Every packaged resource needs a stable, non-empty name for lookup within the pack.

Solutions

  1. Pass a meaningful non-empty name to the File record constructor.
  2. If the name is derived from a path, use the file name component and verify it is non-blank before constructing.
  3. Guard the call site with a check that skips or renames blank-named entries.

Example fix

// before
new ThemePackResource.File(path, "")
// after
new ThemePackResource.File(path, "background.png")
Defensive patterns

Strategy: validation

Validate before calling

if (name == null || name.trim().isEmpty()) throw new IllegalArgumentException("resource name required");

Try / catch

try { resource = new ThemePackResource.File(path, name); } catch (IllegalArgumentException e) { skipEntry(path); }

Prevention

When it happens

Trigger: Constructing new ThemePackResource.File(path, name) with name = "" or whitespace-only; computing the name from a filename that ends up empty after trim.

Common situations: Iterating zip entries and passing an empty derived key; a renaming script that blanked resource names; passing Path.getFileName() results from a root path.

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


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

Appendix: source

Thrown at HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemePackResource.java:76

    /// @param name the stable resource name
    @NotNullByDefault
    record File(Path path, String name) implements ThemePackResource {
        /// Creates a file-backed theme-pack resource named after its file name.
        ///
        /// @param path the resource file path
        public File(Path path) {
            this(path, Objects.requireNonNull(path).getFileName().toString());
        }

        /// Creates a file-backed theme-pack resource.
        ///
        /// @param path the resource file path
        /// @param name the stable resource name
        public File {
            path = Objects.requireNonNull(path).toAbsolutePath().normalize();
            name = Objects.requireNonNull(name).trim();
            if (name.isEmpty()) {
                throw new IllegalArgumentException("Theme-pack resource name is blank");
            }
        }

        /// Opens the file.
        @Override
        public InputStream openStream() throws IOException {
            return Files.newInputStream(path);
        }

        /// Returns the backing file.
        @Override
        public Path file() {
            return path;
        }
    }

    /// A resource stored as an entry inside a zip theme-pack file.
    ///

View on GitHub (pinned to 24702dc5a0)