HMCL-dev/HMCL · error · JsonParseException
Theme-pack author must be an object or a string
Error message
Theme-pack author must be an object or a string
What it means
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.
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.
Example fix
// before (theme.json)
{"author": ["Alice", "Bob"]}
// after
{"author": "Alice"}
// or
{"author": {"name": "Alice"}} Defensive patterns
Strategy: type-guard
Validate before calling
boolean validAuthor(JsonElement e) {
return e instanceof JsonObject || (e != null && e.isJsonPrimitive() && e.getAsJsonPrimitive().isString());
} Type guard
if (!(json instanceof JsonObject) && !(json instanceof JsonPrimitive p && p.isString())) throw new IllegalArgumentException("author must be object or string"); Try / catch
try { ThemePackAuthor a = ThemePackAuthor.fromJson(json); } catch (JsonParseException e) { log.warn("Invalid author element: " + json); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Theme-pack manifest is missing themes array
- Missing author name:
- Manifest is null
- Invalid theme-pack manifest
- Theme packs cannot reference built-in wallpaper
AI-assisted analysis of HMCL-dev/HMCL@24702dc5a0 (2026-09-10).
Data as JSON: /api/errors/7010d660009be2a4.
Report an issue: GitHub.
Appendix: source
Thrown at HMCL/src/main/java/org/jackhuang/hmcl/theme/ThemePackAuthor.java:97
/// Parses author metadata from a JSON object or a plain string.
///
/// @param json the author metadata JSON
/// @return the parsed author metadata, or `null` when `json` is `null`
/// @throws JsonParseException if `json` is neither an object nor a string author name
public static @Nullable ThemePackAuthor fromJson(@Nullable JsonElement json) throws JsonParseException {
if (json == null || json instanceof JsonNull)
return null;
if (json instanceof JsonPrimitive primitive && primitive.isString()) {
try {
return new ThemePackAuthor(LocalizedText.plain(primitive.getAsString()));
} catch (IllegalArgumentException e) {
throw new JsonParseException(e);
}
}
if (!(json instanceof JsonObject jsonObject)) {
throw new JsonParseException("Theme-pack author must be an object or a string");
}
JsonElement nameJson = jsonObject.get("name");
if (nameJson == null) {
throw new JsonParseException("Missing author name: " + json);
}
LocalizedText name = LocalizedText.fromJson(nameJson);
if (name == null) {
throw new JsonParseException("The author name is null");
}
try {
return new ThemePackAuthor(name);
} catch (IllegalArgumentException e) {
throw new JsonParseException(e);
}
}View on GitHub (pinned to 24702dc5a0)