HMCL-dev/HMCL · error · JsonParseException
UUID malformed
Error message
UUID malformed
What it means
Identical to the hyphenated UUIDTypeAdapter: this adapter parses a JSON string into a UUID and wraps any IllegalArgumentException from UUIDs.parse in a JsonParseException reading 'UUID malformed'. Despite the class name suggesting unhyphenated input, both adapters go through UUIDs.parse.
Solutions
- Correct the UUID string in the source JSON to a valid 32-char unhyphenated or 36-char hyphenated form as appropriate.
- Normalize UUIDs (strip or add dashes) before serialization so the stored format matches the adapter in use.
- Catch JsonParseException around deserialization and repair or regenerate the identifier.
Example fix
// before
String raw = "e3f1c2a4b5d6478f90a1b2c3d4e5f6a7-"; // trailing junk
UUID id = UnhyphenatedUUIDTypeAdapter.INSTANCE.read(reader);
// after
String raw = rawInput.trim().replace("-", "");
if (raw.length() == 32 && raw.chars().allMatch(c -> Character.isLetterOrDigit(c) && c < 'g')) {
UUID id = UUIDs.parse(raw);
} Defensive patterns
Strategy: validation
Validate before calling
static boolean isUnhyphenatedUuid(String s) { return s != null && s.matches("[0-9a-fA-F]{32}"); } Type guard
static @Nullable UUID safeParseCompact(String s) { return s != null && s.matches("[0-9a-fA-F]{32}") ? UUIDs.parse(s) : null; } Try / catch
try { return UnhyphenatedUUIDTypeAdapter.INSTANCE.read(reader); } catch (JsonParseException e) { log.warn("Malformed compact UUID", e); return null; } Prevention
- Pick one UUID storage format and normalize on write.
- Validate UUID strings when importing external data.
- Strip whitespace/hyphens before parsing compact UUIDs.
When it happens
Trigger: reader.nextString() yields a string UUIDs.parse cannot decode — wrong length, non-hex characters, or a hyphenated UUID where the compact form is expected (or vice versa).
Common situations: Mojang-style unhyphenated UUID data mixed with hyphenated IDs in stored JSON; truncated or corrupted account/profile files; copy-paste errors in identifiers.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- UUID malformed
- Config is not an object:
- Expected JsonObject but got
- json.toString()
- PortablePath must be a string: " + in.peek()
AI-assisted analysis of HMCL-dev/HMCL@24702dc5a0 (2026-09-10).
Data as JSON: /api/errors/372bc7511989f13e.
Report an issue: GitHub.
Appendix: source
Thrown at HMCLCore/src/main/java/org/jackhuang/hmcl/util/gson/UnhyphenatedUUIDTypeAdapter.java:55
/// Writes a UUID as a lowercase string without hyphens.
@Override
public void write(JsonWriter writer, @Nullable UUID value) throws IOException {
writer.value(value == null ? null : UUIDs.toCompactString(value));
}
/// Reads a UUID from a standard or unhyphenated UUID string.
@Override
public @Nullable UUID read(JsonReader reader) throws IOException {
if (reader.peek() == JsonToken.NULL) {
reader.nextNull();
return null;
}
try {
return UUIDs.parse(reader.nextString());
} catch (IllegalArgumentException e) {
throw new JsonParseException("UUID malformed", e);
}
}
/// Prevents instantiation outside the shared instance.
private UnhyphenatedUUIDTypeAdapter() {
}
}
View on GitHub (pinned to 24702dc5a0)