HMCL-dev/HMCL · error · JsonParseException

ForgeVersion mcversion cannot be null

Error message

ForgeVersion mcversion cannot be null

What it means

Thrown during Gson post-deserialization when a Forge version entry fetched from the BMCLAPI metadata lacks the mcversion field; the JSON payload is malformed or from an incompatible API, so the version list aborts validation.

Solutions

  1. Add the 'mcversion' field to the version entry JSON
  2. Catch JsonParseException and skip entries missing mcversion
  3. Re-download the version list from the mirror

Example fix

// before
{"version": "47.1.3", "files": [...]} // mcversion missing
version.validate();
// after
{"version": "47.1.3", "mcversion": "1.20.1", "files": [...]}
version.validate();
Defensive patterns

Strategy: validation

Validate before calling

if (versionObject.get("mcversion") == null || versionObject.get("mcversion").isJsonNull())
    throw new JsonParseException("ForgeVersion mcversion missing");

Type guard

static boolean hasMcVersion(JsonObject entry) {
    return entry.get("mcversion") instanceof JsonPrimitive p && p.isString() && !p.getAsString().isBlank();
}

Try / catch

try {
    forgeVersion.validate();
} catch (JsonParseException e) {
    LOG.warning("Skipping entry with missing mcversion: " + e.getMessage());
}

Prevention

When it happens

Trigger: Parsing a Forge version list entry without 'mcversion' and calling validate().

Common situations: Partial mirror responses, custom/generated JSON missing the field, or API schema changes breaking deserialization.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at HMCLCore/src/main/java/org/jackhuang/hmcl/download/forge/ForgeBMCLVersionList.java:197

@Override
public void validate() throws JsonParseException {
    if (files == null)
        throw new JsonParseException("ForgeVersion files cannot be null");
    if (version == null)
        throw new JsonParseException("ForgeVersion version cannot be null");
    if (mcversion == null)
        throw new JsonParseException("ForgeVersion mcversion cannot be null");
}

View on GitHub (pinned to 24702dc5a0)