{"record":{"id":"be9926c2ede0a22c","repo":"HMCL-dev/HMCL","slug":"theme-override-must-define-an-object-condition","errorCode":null,"errorMessage":"Theme override must define an object condition","messagePattern":"Theme override must define an object condition","errorType":"validation","errorClass":"JsonParseException","httpStatus":null,"severity":"error","filePath":"HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemeOverride.java","lineNumber":64,"sourceCode":"        }\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\n    /// @return `true` when the override should be applied\n    public boolean matches(ThemeResolveContext context) {\n        return condition.matches(context);\n    }\n","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemeOverride.java#L46-L82","documentation":"A theme override object must contain a 'condition' field that is itself a JSON object. If the field is missing, null, a primitive, or an array, JsonParseException(\"Theme override must define an object condition\") is thrown, because ThemeCondition.fromJson expects an object.","triggerScenarios":"Calling ThemeOverride.fromJson with an object lacking FIELD_CONDITION or where the condition value is not a JsonObject (string, array, null).","commonSituations":"Hand-authored theme packs omit the condition block, misspell the 'condition' key, or encode the condition as a string expression.","solutions":["Add a condition object to the override, e.g. \"condition\": { ... }","Fix the field name/key spelling so it matches the loader's expected condition field","If the override should always apply, use an empty object {} as the condition if the schema allows"],"exampleFix":"// before\n{ \"darker\": 5 }\n// after\n{ \"condition\": { \"os\": \"windows\" }, \"darker\": 5 }","handlingStrategy":"validation","validationCode":"static boolean hasCondition(JsonObject override) {\n    return override.has(\"condition\") && override.get(\"condition\").isJsonObject();\n}","typeGuard":"static boolean hasObjectField(JsonObject o, String field) {\n    return o.get(field) instanceof JsonObject;\n}","tryCatchPattern":"try {\n    ThemeOverride o = ThemeOverride.fromJson(el);\n} catch (JsonParseException e) {\n    log.warn(\"Skipping override: \" + e.getMessage());\n}","preventionTips":["Include a condition object in every override, even if empty","Use the documented field names exactly (condition)","Lint theme packs for required keys before distribution"],"tags":["json","theme","schema"],"backgroundTag":"missing-required-config-field","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"}