{"record":{"id":"94d0a824bbb296fd","repo":"HMCL-dev/HMCL","slug":"theme-condition-array-is-empty","errorCode":null,"errorMessage":"Theme condition array is empty: ","messagePattern":"Theme condition array is empty: ","errorType":"validation","errorClass":"JsonParseException","httpStatus":null,"severity":"error","filePath":"HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemeCondition.java","lineNumber":139,"sourceCode":"            } else {\n                JsonArray array = new JsonArray();\n                for (String value : entry.getValue()) {\n                    array.add(value);\n                }\n                object.add(entry.getKey(), array);\n            }\n        }\n        return object;\n    }\n\n    /// Reads one condition field value.\n    private static Set<String> readAcceptedValues(String key, JsonElement element) throws JsonParseException {\n        LinkedHashSet<String> values = new LinkedHashSet<>();\n        if (element instanceof JsonPrimitive primitive && primitive.isString()) {\n            values.add(normalizeValue(key, primitive.getAsString()));\n        } else if (element instanceof JsonArray array) {\n            if (array.isEmpty()) {\n                throw new JsonParseException(\"Theme condition array is empty: \" + key);\n            }\n\n            for (JsonElement item : array) {\n                if (!(item instanceof JsonPrimitive primitive) || !primitive.isString()) {\n                    throw new JsonParseException(\"Theme condition array must contain strings: \" + key);\n                }\n                values.add(normalizeValue(key, primitive.getAsString()));\n            }\n        } else {\n            throw new JsonParseException(\"Theme condition value must be a string or string array: \" + key);\n        }\n        return values;\n    }\n\n    /// Normalizes and validates a condition key.\n    private static String normalizeKey(String key) {\n        Objects.requireNonNull(key);\n","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemeCondition.java#L121-L157","documentation":"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.","triggerScenarios":"A theme JSON condition field whose value is an empty array, e.g. {\"conditions\": {\"os\": []}}, passed through ThemeCondition.fromJson.","commonSituations":"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.","solutions":["Put at least one string in the condition array, e.g. \"os\": [\"windows\"].","Delete the condition key entirely if no values should be accepted.","Pre-validate theme JSON: reject or drop condition entries whose array is empty before calling fromJson.","Fix the theme-generator/template so it omits conditions with no values."],"exampleFix":"// before (theme.json)\n// \"conditions\": { \"os\": [] }\n// after\n\"conditions\": { \"os\": [\"windows\", \"linux\"] }","handlingStrategy":"validation","validationCode":"JsonElement v = obj.get(\"os\");\nboolean ok = v != null && !(v instanceof JsonArray a && a.isEmpty());","typeGuard":"static boolean isNonEmptyStringArray(JsonElement e) {\n    return e instanceof JsonArray a && !a.isEmpty();\n}","tryCatchPattern":"try {\n    ThemeCondition c = ThemeCondition.fromJson(element);\n} catch (JsonParseException e) {\n    LOG.warning(\"Bad theme condition: \" + e.getMessage());\n}","preventionTips":["Omit condition keys instead of writing empty arrays","Lint theme JSON for empty arrays before distribution","If generating themes, skip conditions with no accepted values","Check theme files after manual edits that remove values"],"tags":["json","theme","condition","empty-array"],"backgroundTag":"schema-validation-failed","analyzedSha":"24702dc5a0214034f4c27166d5fd30cad08cec19","analyzedAt":"2026-09-10T12:36:46.680Z","contentChangedAt":"2026-09-10T12:36:46.680Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}