HMCL-dev/HMCL · error · JsonParseException

Unsupported brightness condition value:

Error message

Unsupported brightness condition value: 

What it means

For the "brightness" condition key, normalizeValue only accepts "light" or "dark" (case-insensitive). Any other value throws this JsonParseException, keeping brightness conditions limited to the two supported appearance modes.

Solutions

  1. Use only "light" or "dark" for the brightness condition, e.g. "brightness": ["dark"].
  2. Move non-brightness concepts (e.g. system-default) to a supported condition key or drop them.
  3. Normalize author input to light/dark before writing the theme file.
  4. Catch JsonParseException around fromJson and list the allowed values (light, dark) in the error shown to the user.

Example fix

// before (theme.json)
// "brightness": ["auto"]
// after
"brightness": ["light", "dark"]
Defensive patterns

Strategy: validation

Validate before calling

boolean ok = "light".equalsIgnoreCase(v) || "dark".equalsIgnoreCase(v);

Type guard

static boolean isBrightnessValue(String v) {
    return "light".equalsIgnoreCase(v) || "dark".equalsIgnoreCase(v);
}

Try / catch

try {
    ThemeCondition c = ThemeCondition.fromJson(element);
} catch (JsonParseException e) {
    LOG.warning("Bad brightness value (use light/dark): " + e.getMessage());
}

Prevention

When it happens

Trigger: ThemeCondition.fromJson reading {"brightness": ["system"]} or {"brightness": "auto"} — a value that is not light/dark after lowercasing.

Common situations: Theme authors guessing at brightness vocabulary ("auto", "system", "high-contrast"); copy-paste from other theming systems; typos like "darke".

Related errors


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

Appendix: source

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

        }
        return normalized;
    }

    /// Normalizes and validates one condition value.
    private static String normalizeValue(String key, String value) {
        Objects.requireNonNull(key);
        Objects.requireNonNull(value);

        String trimmed = value.trim();
        if (trimmed.isEmpty()) {
            throw new JsonParseException("Empty theme condition value for " + key);
        }
        String normalized = trimmed.toLowerCase(Locale.ROOT);

        return switch (key) {
            case KEY_BRIGHTNESS -> switch (normalized) {
                    case "light", "dark" -> normalized;
                    default -> throw new JsonParseException("Unsupported brightness condition value: " + value);
                };
            case KEY_OS -> normalizeOperatingSystemValue(normalized, value);
            case KEY_LANGUAGE -> normalized;
            default -> trimmed;
        };
    }

    /// Normalizes an operating system condition value.
    private static String normalizeOperatingSystemValue(String normalized, String original) {
        String value = switch (normalized) {
            case "win", "windows" -> "windows";
            case "mac", "macos", "osx" -> "macos";
            case "linux" -> "linux";
            case "freebsd" -> "freebsd";
            case "unknown", "universal" -> "unknown";
            default -> normalized;
        };

View on GitHub (pinned to 24702dc5a0)