HMCL-dev/HMCL · error · IOException

Bad Build-Number

Error message

Bad Build-Number

What it means

AuthlibInjectorArtifactInfo.from parses the jar manifest's Build-Number attribute as an integer; a non-numeric value throws IOException "Bad Build-Number" wrapping the NumberFormatException, and a missing attribute throws "Missing Build-Number". This validates that the artifact is a properly built authlib-injector release.

Solutions

  1. Use an official authlib-injector release jar with a valid Build-Number
  2. Re-download the artifact if the manifest was corrupted or stripped
  3. When building locally, run the release build so Build-Number is populated

Example fix

// before
// manifest Build-Number: 'dev'
AuthlibInjectorArtifactInfo.from(jar); // throws Bad Build-Number
// after
// download official release, e.g. authlib-injector-1.2.5.jar
AuthlibInjectorArtifactInfo.from(Path.of("authlib-injector-1.2.5.jar"));
Defensive patterns

Strategy: try-catch

Validate before calling

try (JarFile jf = new JarFile(jar.toFile())) {
    String bn = jf.getManifest().getMainAttributes().getValue("Build-Number");
    if (bn == null || !bn.matches("\\d+")) {
        throw new IOException("Jar has invalid Build-Number: " + bn);
    }
}

Try / catch

try {
    AuthlibInjectorArtifactInfo info = AuthlibInjectorArtifactInfo.from(path);
} catch (IOException e) {
    log.error("Invalid artifact build metadata: {}", e.getMessage());
    // re-download official release
}

Prevention

When it happens

Trigger: Reading a jar whose manifest Build-Number attribute is absent or non-numeric (e.g. "abc", empty, or locally rebuilt without the build plugin).

Common situations: Building authlib-injector from source without release tooling; corrupted manifest in a re-zipped jar; third-party or tampered downloads.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

Thrown at HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorArtifactInfo.java:49

        try (JarFile jarFile = new JarFile(location.toFile())) {
            Attributes attributes = jarFile.getManifest().getMainAttributes();

            String title = Optional.ofNullable(attributes.getValue("Implementation-Title"))
                    .orElseThrow(() -> new IOException("Missing Implementation-Title"));
            if (!"authlib-injector".equals(title)) {
                throw new IOException("Bad Implementation-Title");
            }

            String version = Optional.ofNullable(attributes.getValue("Implementation-Version"))
                    .orElseThrow(() -> new IOException("Missing Implementation-Version"));

            int buildNumber;
            try {
                buildNumber = Optional.ofNullable(attributes.getValue("Build-Number"))
                        .map(Integer::parseInt)
                        .orElseThrow(() -> new IOException("Missing Build-Number"));
            } catch (NumberFormatException e) {
                throw new IOException("Bad Build-Number", e);
            }
            return new AuthlibInjectorArtifactInfo(buildNumber, version, location.toAbsolutePath());
        }
    }

    @Override
    public @NotNull String toString() {
        return "authlib-injector [buildNumber=" + buildNumber + ", version=" + version + "]";
    }
}

View on GitHub (pinned to 24702dc5a0)