HMCL-dev/HMCL · error · IllegalArgumentException
Theme condition field has no accepted values:
Error message
Theme condition field has no accepted values:
What it means
When building a ThemeCondition from a requirements map, every condition field must accept at least one value. If a field's value set is empty the condition can never match, so the constructor rejects it eagerly with IllegalArgumentException.
Solutions
- Add at least one accepted value to the condition field, e.g. "os" -> Set.of("windows", "linux").
- Remove the empty condition field from the requirements map entirely if the condition is unnecessary.
- Validate the map before constructing: skip or reject entries whose value set is empty.
- If values are computed at runtime, fall back to a known-good default value set when the computed set is empty.
Example fix
// before
Map<String, Set<String>> req = new LinkedHashMap<>();
req.put("os", new LinkedHashSet<>()); // empty -> throws
ThemeCondition c = new ThemeCondition(req);
// after
Map<String, Set<String>> req = new LinkedHashMap<>();
if (!osValues.isEmpty()) {
req.put("os", osValues);
}
ThemeCondition c = new ThemeCondition(req); Defensive patterns
Strategy: validation
Validate before calling
for (Map.Entry<String, Set<String>> e : requirements.entrySet()) {
if (e.getKey().trim().isEmpty() || e.getValue().isEmpty())
throw new IllegalArgumentException("Invalid condition entry: " + e.getKey());
} Try / catch
try {
ThemeCondition c = new ThemeCondition(requirements);
} catch (IllegalArgumentException e) {
LOG.warning("Dropping unsatisfiable condition: " + e.getMessage());
} Prevention
- Never put a key with an empty Set in the requirements map
- Filter out empty value sets before constructing conditions
- Ensure value-filtering logic keeps at least one element or removes the key
- Unit-test condition construction with edge-case maps
When it happens
Trigger: Calling the ThemeCondition constructor (or the programmatic builder path, e.g. ThemeCondition.of / fromJson feeding it) with a map such as Map.of("os", Set.of()) — a key present with an empty value set.
Common situations: Building conditions programmatically after filtering values (a filter removed everything); deserializing JSON where a condition array was empty upstream; refactors that initialize a LinkedHashSet but never populate it.
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
- Empty theme condition value for
- Theme condition array is empty:
- Theme condition array must contain strings:
- Theme condition key is blank
- Theme condition value must be a string or string array:
AI-assisted analysis of HMCL-dev/HMCL@24702dc5a0 (2026-09-10).
Data as JSON: /api/errors/c33f9a076b7b6fdc.
Report an issue: GitHub.
Appendix: source
Thrown at HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemeCondition.java:69
/// Condition key for the current UI language.
static final String KEY_LANGUAGE = "language";
/// Supported operating system condition values.
private static final Set<String> SUPPORTED_OS_VALUES = Set.of("windows", "macos", "linux", "freebsd", "unknown");
/// Creates a condition from normalized accepted values.
///
/// @param requirements normalized accepted values keyed by condition name
public ThemeCondition {
Objects.requireNonNull(requirements);
LinkedHashMap<String, Set<String>> copy = new LinkedHashMap<>();
for (Map.Entry<String, Set<String>> entry : requirements.entrySet()) {
String key = normalizeKey(entry.getKey());
Set<String> values = entry.getValue();
if (values.isEmpty()) {
throw new IllegalArgumentException("Theme condition field has no accepted values: " + key);
}
LinkedHashSet<String> valueCopy = new LinkedHashSet<>();
for (String value : values) {
valueCopy.add(normalizeValue(key, value));
}
copy.put(key, Collections.unmodifiableSet(valueCopy));
}
requirements = Collections.unmodifiableMap(copy);
}
/// Parses a theme condition from a JSON object.
///
/// @param object the condition object
/// @return the parsed condition
/// @throws JsonParseException if the condition contains malformed values
public static ThemeCondition fromJson(JsonObject object) throws JsonParseException {
Objects.requireNonNull(object);View on GitHub (pinned to 24702dc5a0)