{"record":{"id":"7010d660009be2a4","repo":"HMCL-dev/HMCL","slug":"theme-pack-author-must-be-an-object-or-a-string","errorCode":null,"errorMessage":"Theme-pack author must be an object or a string","messagePattern":"Theme-pack author must be an object or a string","errorType":"validation","errorClass":"JsonParseException","httpStatus":null,"severity":"error","filePath":"HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemePackAuthor.java","lineNumber":97,"sourceCode":"    /// Parses author metadata from a JSON object or a plain string.\n    ///\n    /// @param json the author metadata JSON\n    /// @return the parsed author metadata, or `null` when `json` is `null`\n    /// @throws JsonParseException if `json` is neither an object nor a string author name\n    public static @Nullable ThemePackAuthor fromJson(@Nullable JsonElement json) throws JsonParseException {\n        if (json == null || json instanceof JsonNull)\n            return null;\n\n        if (json instanceof JsonPrimitive primitive && primitive.isString()) {\n            try {\n                return new ThemePackAuthor(LocalizedText.plain(primitive.getAsString()));\n            } catch (IllegalArgumentException e) {\n                throw new JsonParseException(e);\n            }\n        }\n\n        if (!(json instanceof JsonObject jsonObject)) {\n            throw new JsonParseException(\"Theme-pack author must be an object or a string\");\n        }\n\n        JsonElement nameJson = jsonObject.get(\"name\");\n        if (nameJson == null) {\n            throw new JsonParseException(\"Missing author name: \" + json);\n        }\n\n        LocalizedText name = LocalizedText.fromJson(nameJson);\n        if (name == null) {\n            throw new JsonParseException(\"The author name is null\");\n        }\n\n        try {\n            return new ThemePackAuthor(name);\n        } catch (IllegalArgumentException e) {\n            throw new JsonParseException(e);\n        }\n    }","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemePackAuthor.java#L79-L115","documentation":"Thrown by ThemePackAuthor.fromJson when a theme-pack manifest's author field is neither a JSON object nor a string. The library accepts either a plain string author or an object with a localized 'name' field; anything else (number, boolean, array, null) is rejected so malformed manifests fail loudly at load time instead of producing a broken author record.","triggerScenarios":"Parsing a theme.json/manifest whose \"author\" key is set to a JSON number, boolean, array, or null while deserializing via ThemePackAuthor.fromJson / ThemePackManifest.fromJson.","commonSituations":"Hand-edited theme-pack manifests, third-party tools generating manifests with numeric author IDs, or pack authors writing {\"author\": [\"a\",\"b\"]} to express multiple authors instead of one string or one object.","solutions":["Change the manifest's \"author\" value to a plain string, e.g. {\"author\": \"Alice\"}.","Or use the object form with a \"name\" field: {\"author\": {\"name\": \"Alice\"}} (name may be a LocalizedText object).","Remove arrays/numbers/booleans; multiple authors or extra metadata are not supported in this field.","Re-export the theme pack with ThemePackExporter so the manifest is generated correctly."],"exampleFix":"// before (theme.json)\n{\"author\": [\"Alice\", \"Bob\"]}\n// after\n{\"author\": \"Alice\"}\n// or\n{\"author\": {\"name\": \"Alice\"}}","handlingStrategy":"type-guard","validationCode":"boolean validAuthor(JsonElement e) {\n    return e instanceof JsonObject || (e != null && e.isJsonPrimitive() && e.getAsJsonPrimitive().isString());\n}","typeGuard":"if (!(json instanceof JsonObject) && !(json instanceof JsonPrimitive p && p.isString())) throw new IllegalArgumentException(\"author must be object or string\");","tryCatchPattern":"try { ThemePackAuthor a = ThemePackAuthor.fromJson(json); } catch (JsonParseException e) { log.warn(\"Invalid author element: \" + json); }","preventionTips":["Always author manifests as {\"author\": \"Name\"} or {\"author\": {\"name\": ...}}","Validate manifests with a JSON schema before distributing packs","Never encode multiple authors as an array"],"tags":["json","theme-pack","manifest","validation"],"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"}