HMCL-dev/HMCL · error · JsonParseException

Theme condition array is empty:

Error message

Theme condition array is empty: 

What it means

ThemeCondition.readAcceptedValues parses a condition field's JSON value. A JSON array value must contain at least one string; an empty array would make the condition unsatisfiable, so it is rejected with JsonParseException during fromJson.

Solutions

  1. Put at least one string in the condition array, e.g. "os": ["windows"].
  2. Delete the condition key entirely if no values should be accepted.
  3. Pre-validate theme JSON: reject or drop condition entries whose array is empty before calling fromJson.
  4. Fix the theme-generator/template so it omits conditions with no values.

Example fix

// before (theme.json)
// "conditions": { "os": [] }
// after
"conditions": { "os": ["windows", "linux"] }
Defensive patterns

Strategy: validation

Validate before calling

JsonElement v = obj.get("os");
boolean ok = v != null && !(v instanceof JsonArray a && a.isEmpty());

Type guard

static boolean isNonEmptyStringArray(JsonElement e) {
    return e instanceof JsonArray a && !a.isEmpty();
}

Try / catch

try {
    ThemeCondition c = ThemeCondition.fromJson(element);
} catch (JsonParseException e) {
    LOG.warning("Bad theme condition: " + e.getMessage());
}

Prevention

When it happens

Trigger: A theme JSON condition field whose value is an empty array, e.g. {"conditions": {"os": []}}, passed through ThemeCondition.fromJson.

Common situations: Hand-edited theme files where all values were deleted but the key kept; tools generating themes that emit empty arrays when no values matched; templates with placeholder arrays never filled in.

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/94d0a824bbb296fd. Report an issue: GitHub.

Appendix: source

Thrown at HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemeCondition.java:139

            } else {
                JsonArray array = new JsonArray();
                for (String value : entry.getValue()) {
                    array.add(value);
                }
                object.add(entry.getKey(), array);
            }
        }
        return object;
    }

    /// Reads one condition field value.
    private static Set<String> readAcceptedValues(String key, JsonElement element) throws JsonParseException {
        LinkedHashSet<String> values = new LinkedHashSet<>();
        if (element instanceof JsonPrimitive primitive && primitive.isString()) {
            values.add(normalizeValue(key, primitive.getAsString()));
        } else if (element instanceof JsonArray array) {
            if (array.isEmpty()) {
                throw new JsonParseException("Theme condition array is empty: " + key);
            }

            for (JsonElement item : array) {
                if (!(item instanceof JsonPrimitive primitive) || !primitive.isString()) {
                    throw new JsonParseException("Theme condition array must contain strings: " + key);
                }
                values.add(normalizeValue(key, primitive.getAsString()));
            }
        } else {
            throw new JsonParseException("Theme condition value must be a string or string array: " + key);
        }
        return values;
    }

    /// Normalizes and validates a condition key.
    private static String normalizeKey(String key) {
        Objects.requireNonNull(key);

View on GitHub (pinned to 24702dc5a0)