{"record":{"id":"c071d10d3ca832e2","repo":"HMCL-dev/HMCL","slug":"invalid-theme-override","errorCode":null,"errorMessage":"Invalid theme override","messagePattern":"Invalid theme override","errorType":"validation","errorClass":"JsonParseException","httpStatus":null,"severity":"error","filePath":"HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemeOverride.java","lineNumber":59,"sourceCode":"    public ThemeOverride {\n        Objects.requireNonNull(condition);\n        Objects.requireNonNull(appearance);\n        if (appearance.isEmpty()) {\n            throw new IllegalArgumentException(\"Theme override does not define any appearance fields\");\n        }\n    }\n\n    /// Parses a theme override from JSON.\n    ///\n    /// @param element the override object\n    /// @return the parsed override\n    /// @throws JsonParseException if the override is malformed\n    static @Nullable ThemeOverride fromJson(@Nullable JsonElement element) throws JsonParseException {\n        if (element == null || element.isJsonNull())\n            return null;\n\n        if (!(element instanceof JsonObject object)) {\n            throw new JsonParseException(\"Invalid theme override\");\n        }\n\n        JsonElement conditionElement = object.get(FIELD_CONDITION);\n        if (!(conditionElement instanceof JsonObject conditionObject)) {\n            throw new JsonParseException(\"Theme override must define an object condition\");\n        }\n\n        ThemeCondition condition = ThemeCondition.fromJson(conditionObject);\n        ThemeAppearance appearance = ThemeAppearance.fromJson(object);\n        if (appearance.isEmpty()) {\n            throw new JsonParseException(\"Theme override does not define any appearance fields\");\n        }\n        return new ThemeOverride(condition, appearance);\n    }\n\n    /// Returns whether this override matches the given resolution context.\n    ///\n    /// @param context the context to test","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemeOverride.java#L41-L77","documentation":"fromJson parses a theme override from JSON and requires the element to be a JSON object. If the element is present but is an array, string, number, or boolean, JsonParseException(\"Invalid theme override\") is thrown. This guards the theme pack schema so downstream code can safely read fields like 'condition'.","triggerScenarios":"Calling ThemeOverride.fromJson with a non-null JsonElement that is not a JsonObject (e.g. a JsonArray, JsonPrimitive, or JsonNull is excluded earlier).","commonSituations":"A theme pack JSON defines an override as a list of overrides instead of an object, quotes the override value as a string, or hand-edits the theme file and changes the structure.","solutions":["Wrap the override value in a JSON object in the theme pack file","Validate the theme pack JSON structure before loading (element must be an object)","Check for version/schema drift between the theme pack and the loader"],"exampleFix":"// before\n\"overrides\": [ { \"condition\": {}, \"darker\": 5 } ]\n// after\n\"overrides\": { \"condition\": {}, \"darker\": 5 }","handlingStrategy":"validation","validationCode":"static boolean isValidOverride(JsonElement e) {\n    return e != null && !e.isJsonNull() && e.isJsonObject();\n}","typeGuard":"static boolean isJsonObject(JsonElement e) {\n    return e instanceof JsonObject;\n}","tryCatchPattern":"try {\n    ThemeOverride o = ThemeOverride.fromJson(el);\n} catch (JsonParseException e) {\n    log.warn(\"Skipping invalid theme override: \" + e.getMessage());\n}","preventionTips":["Always define overrides as JSON objects in theme packs","Validate theme pack JSON with a schema before loading","Check the theme pack format version matches the loader"],"tags":["json","theme","schema"],"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-16T04:17:20.429Z"}