{"record":{"id":"c33f9a076b7b6fdc","repo":"HMCL-dev/HMCL","slug":"theme-condition-field-has-no-accepted-values","errorCode":null,"errorMessage":"Theme condition field has no accepted values: ","messagePattern":"Theme condition field has no accepted values: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemeCondition.java","lineNumber":69,"sourceCode":"\n    /// Condition key for the current UI language.\n    static final String KEY_LANGUAGE = \"language\";\n\n    /// Supported operating system condition values.\n    private static final Set<String> SUPPORTED_OS_VALUES = Set.of(\"windows\", \"macos\", \"linux\", \"freebsd\", \"unknown\");\n\n    /// Creates a condition from normalized accepted values.\n    ///\n    /// @param requirements normalized accepted values keyed by condition name\n    public ThemeCondition {\n        Objects.requireNonNull(requirements);\n\n        LinkedHashMap<String, Set<String>> copy = new LinkedHashMap<>();\n        for (Map.Entry<String, Set<String>> entry : requirements.entrySet()) {\n            String key = normalizeKey(entry.getKey());\n            Set<String> values = entry.getValue();\n            if (values.isEmpty()) {\n                throw new IllegalArgumentException(\"Theme condition field has no accepted values: \" + key);\n            }\n\n            LinkedHashSet<String> valueCopy = new LinkedHashSet<>();\n            for (String value : values) {\n                valueCopy.add(normalizeValue(key, value));\n            }\n            copy.put(key, Collections.unmodifiableSet(valueCopy));\n        }\n        requirements = Collections.unmodifiableMap(copy);\n    }\n\n    /// Parses a theme condition from a JSON object.\n    ///\n    /// @param object the condition object\n    /// @return the parsed condition\n    /// @throws JsonParseException if the condition contains malformed values\n    public static ThemeCondition fromJson(JsonObject object) throws JsonParseException {\n        Objects.requireNonNull(object);","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemeCondition.java#L51-L87","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nMap<String, Set<String>> req = new LinkedHashMap<>();\nreq.put(\"os\", new LinkedHashSet<>()); // empty -> throws\nThemeCondition c = new ThemeCondition(req);\n// after\nMap<String, Set<String>> req = new LinkedHashMap<>();\nif (!osValues.isEmpty()) {\n    req.put(\"os\", osValues);\n}\nThemeCondition c = new ThemeCondition(req);","handlingStrategy":"validation","validationCode":"for (Map.Entry<String, Set<String>> e : requirements.entrySet()) {\n    if (e.getKey().trim().isEmpty() || e.getValue().isEmpty())\n        throw new IllegalArgumentException(\"Invalid condition entry: \" + e.getKey());\n}","typeGuard":null,"tryCatchPattern":"try {\n    ThemeCondition c = new ThemeCondition(requirements);\n} catch (IllegalArgumentException e) {\n    LOG.warning(\"Dropping unsatisfiable condition: \" + e.getMessage());\n}","preventionTips":["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"],"tags":["theme","condition","validation","empty-collection"],"backgroundTag":"empty-required-field","analyzedSha":"24702dc5a0214034f4c27166d5fd30cad08cec19","analyzedAt":"2026-09-10T12:36:46.680Z","contentChangedAt":"2026-09-10T12:36:46.680Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}