{"record":{"id":"372bc7511989f13e","repo":"HMCL-dev/HMCL","slug":"uuid-malformed-372bc7","errorCode":null,"errorMessage":"UUID malformed","messagePattern":"UUID malformed","errorType":"exception","errorClass":"JsonParseException","httpStatus":null,"severity":"error","filePath":"HMCLCore/src/main/java/org/jackhuang/hmcl/util/gson/UnhyphenatedUUIDTypeAdapter.java","lineNumber":55,"sourceCode":"\n    /// Writes a UUID as a lowercase string without hyphens.\n    @Override\n    public void write(JsonWriter writer, @Nullable UUID value) throws IOException {\n        writer.value(value == null ? null : UUIDs.toCompactString(value));\n    }\n\n    /// Reads a UUID from a standard or unhyphenated UUID string.\n    @Override\n    public @Nullable UUID read(JsonReader reader) throws IOException {\n        if (reader.peek() == JsonToken.NULL) {\n            reader.nextNull();\n            return null;\n        }\n\n        try {\n            return UUIDs.parse(reader.nextString());\n        } catch (IllegalArgumentException e) {\n            throw new JsonParseException(\"UUID malformed\", e);\n        }\n    }\n\n    /// Prevents instantiation outside the shared instance.\n    private UnhyphenatedUUIDTypeAdapter() {\n    }\n}\n","sourceCodeStart":37,"sourceCodeEnd":63,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCLCore/src/main/java/org/jackhuang/hmcl/util/gson/UnhyphenatedUUIDTypeAdapter.java#L37-L63","documentation":"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.","triggerScenarios":"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).","commonSituations":"Mojang-style unhyphenated UUID data mixed with hyphenated IDs in stored JSON; truncated or corrupted account/profile files; copy-paste errors in identifiers.","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."],"exampleFix":"// before\nString raw = \"e3f1c2a4b5d6478f90a1b2c3d4e5f6a7-\"; // trailing junk\nUUID id = UnhyphenatedUUIDTypeAdapter.INSTANCE.read(reader);\n\n// after\nString raw = rawInput.trim().replace(\"-\", \"\");\nif (raw.length() == 32 && raw.chars().allMatch(c -> Character.isLetterOrDigit(c) && c < 'g')) {\n    UUID id = UUIDs.parse(raw);\n}","handlingStrategy":"validation","validationCode":"static boolean isUnhyphenatedUuid(String s) { return s != null && s.matches(\"[0-9a-fA-F]{32}\"); }","typeGuard":"static @Nullable UUID safeParseCompact(String s) { return s != null && s.matches(\"[0-9a-fA-F]{32}\") ? UUIDs.parse(s) : null; }","tryCatchPattern":"try { return UnhyphenatedUUIDTypeAdapter.INSTANCE.read(reader); } catch (JsonParseException e) { log.warn(\"Malformed compact UUID\", e); return null; }","preventionTips":["Pick one UUID storage format and normalize on write.","Validate UUID strings when importing external data.","Strip whitespace/hyphens before parsing compact UUIDs."],"tags":["json","uuid","gson","format"],"backgroundTag":"invalid-identifier-format","analyzedSha":"24702dc5a0214034f4c27166d5fd30cad08cec19","analyzedAt":"2026-09-10T12:36:46.680Z","contentChangedAt":"2026-09-10T12:36:46.680Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}