HMCL-dev/HMCL · error · JsonParseException
Empty theme condition value for
Error message
Empty theme condition value for
What it means
ThemeCondition.normalizeValue trims each condition value and rejects ones that are empty after trimming. A blank value can never match anything, so fromJson fails with this JsonParseException naming the condition key.
Solutions
- Replace the empty string with a real value, e.g. "os": ["windows"].
- Remove the empty entry from the array (or delete the condition key if no values remain).
- Filter blank strings out of condition values before building the ThemeCondition.
- Catch JsonParseException and point the user at the offending key in their theme file.
Example fix
// before (theme.json) // "os": ["windows", ""] // after "os": ["windows"]
Defensive patterns
Strategy: validation
Validate before calling
boolean ok = values.stream().allMatch(v -> v != null && !v.trim().isEmpty());
Type guard
static boolean hasNoBlankValues(java.util.Collection<String> values) {
return values.stream().allMatch(v -> v != null && !v.trim().isEmpty());
} Try / catch
try {
ThemeCondition c = ThemeCondition.fromJson(element);
} catch (JsonParseException e) {
LOG.warning("Blank condition value: " + e.getMessage());
} Prevention
- Never leave "" or whitespace-only strings in condition arrays
- Filter blank strings before constructing conditions
- Check generator templates so unset variables don't emit empty strings
- Review theme files after bulk edits that may leave empty strings
When it happens
Trigger: A theme JSON condition value that is "" or " ", e.g. {"os": ["windows", " "]} or {"language": ""}, passed through ThemeCondition.fromJson (or the ThemeCondition constructor path).
Common situations: Hand-edited theme files with leftover empty strings after deleting a value; editors saving placeholder quotes; generators emitting empty strings when a variable is unset.
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
- Theme condition array is empty:
- Theme condition array must contain strings:
- Theme condition value must be a string or string array:
- Theme condition key is blank
- Unsupported brightness condition value:
AI-assisted analysis of HMCL-dev/HMCL@24702dc5a0 (2026-09-10).
Data as JSON: /api/errors/1bb1e6c55e83fb46.
Report an issue: GitHub.
Appendix: source
Thrown at HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemeCondition.java:172
/// Normalizes and validates a condition key.
private static String normalizeKey(String key) {
Objects.requireNonNull(key);
String normalized = key.trim();
if (normalized.isEmpty()) {
throw new JsonParseException("Theme condition key is blank");
}
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";View on GitHub (pinned to 24702dc5a0)