{"record":{"id":"acc1caeb28f2d9fb","repo":"HMCL-dev/HMCL","slug":"theme-pack-theme-must-be-an-object","errorCode":null,"errorMessage":"Theme-pack theme must be an object","messagePattern":"Theme-pack theme must be an object","errorType":"validation","errorClass":"JsonParseException","httpStatus":null,"severity":"error","filePath":"HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemePackManifest.java","lineNumber":151,"sourceCode":"            if (themeId.equals(theme.id())) {\n                return theme;\n            }\n        }\n        return null;\n    }\n\n    /// Reads the required theme declaration.\n    private static List<Theme> readThemes(JsonObject object) {\n        boolean hasSingleTheme = object.has(\"theme\");\n        boolean hasMultipleThemes = object.has(\"themes\");\n        if (hasSingleTheme == hasMultipleThemes) {\n            throw new JsonParseException(\"Theme-pack manifest must declare exactly one of theme or themes\");\n        }\n\n        if (hasSingleTheme) {\n            JsonElement element = object.get(\"theme\");\n            if (!(element instanceof JsonObject themeObject)) {\n                throw new JsonParseException(\"Theme-pack theme must be an object\");\n            }\n            return List.of(Theme.fromJson(themeObject, false));\n        }\n\n        JsonElement element = object.get(\"themes\");\n        if (!(element instanceof JsonArray array)) {\n            throw new JsonParseException(\"Theme-pack manifest is missing themes array\");\n        }\n        if (array.isEmpty()) {\n            throw new JsonParseException(\"Theme-pack themes array must declare at least one theme\");\n        }\n\n        ArrayList<Theme> themes = new ArrayList<>(array.size());\n        for (JsonElement item : array) {\n            if (!(item instanceof JsonObject themeObject)) {\n                throw new JsonParseException(\"Theme-pack theme must be an object\");\n            }\n            themes.add(Theme.fromJson(themeObject, true));","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemePackManifest.java#L133-L169","documentation":"Thrown by readThemes when the manifest's \"theme\" key exists but its value is not a JSON object. A single-theme declaration must be an object holding the theme fields; strings, numbers, booleans, or arrays are rejected.","triggerScenarios":"Parsing a manifest where \"theme\" is present but its JsonElement is not a JsonObject (e.g. a quoted string, number, or array).","commonSituations":"\"theme\": \"mytheme\" — using a name string instead of an inline object; JSON typo like an unbalanced brace collapsing the object into a string; tools serializing the theme as a reference/id rather than an object.","solutions":["Make \"theme\" a JSON object with the theme fields: { \"theme\": { \"id\": \"main\", ... } }.","If you meant to reference an external theme by id, instead inline the full theme definition — string references are not supported.","Validate the JSON structure (e.g. with a JSON linter) to catch brace/quote mistakes that turn the object into another type."],"exampleFix":"// before\n{ \"theme\": \"mytheme\" }\n// after\n{ \"theme\": { \"id\": \"mytheme\", \"backgroundColor\": \"#1e1f22\" } }","handlingStrategy":"type-guard","validationCode":"JsonElement t = manifest.get(\"theme\");\nif (t != null && !(t instanceof JsonObject)) {\n    throw new IllegalArgumentException(\"'theme' must be a JSON object, got: \" + t.getClass().getSimpleName());\n}","typeGuard":"static boolean isThemeObject(JsonElement e) {\n    return e instanceof JsonObject;\n}","tryCatchPattern":"try {\n    ThemePackManifest.read(json);\n} catch (JsonParseException e) {\n    if (e.getMessage().equals(\"Theme-pack theme must be an object\")) {\n        // show a manifest structure error pointing at the 'theme' key\n    }\n}","preventionTips":["Always declare 'theme' as an inline JSON object with the theme fields.","Validate manifest JSON structure with a schema or linter before loading."],"tags":["theme-pack","manifest","json","type-mismatch"],"backgroundTag":"json-parse-error","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"}