{"record":{"id":"0129915b09657684","repo":"HMCL-dev/HMCL","slug":"offline-account-configuration-malformed","errorCode":null,"errorMessage":"Offline account configuration malformed.","messagePattern":"Offline account configuration malformed\\.","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"HMCLCore/src/main/java/org/jackhuang/hmcl/auth/offline/OfflineAccountFactory.java","lineNumber":74,"sourceCode":"        UUID uuid;\n        Skin skin;\n        if (additionalData != null) {\n            data = (AdditionalData) additionalData;\n            uuid = data.uuid == null ? getUUIDFromUserName(username) : data.uuid;\n            skin = data.skin;\n        } else {\n            uuid = getUUIDFromUserName(username);\n            skin = null;\n        }\n        return new OfflineAccount(AccountID.generate(), downloader, username, uuid, skin);\n    }\n\n    @Override\n    public OfflineAccount fromStorage(JsonObject metadata, JsonObject privateData) {\n        AccountID accountID = Account.readAccountID(metadata);\n        String profileName = JsonUtils.getString(metadata, \"profileName\");\n        if (profileName == null) {\n            throw new IllegalStateException(\"Offline account configuration malformed.\");\n        }\n        String profileIDText = JsonUtils.getString(metadata, \"profileID\");\n        UUID profileID = profileIDText != null\n                ? UUIDs.parse(profileIDText)\n                : getUUIDFromUserName(profileName);\n        Skin skin = Skin.fromStorage(metadata.get(\"skin\") instanceof JsonObject skinObject ? skinObject : null);\n\n        return new OfflineAccount(accountID, downloader, profileName, profileID, skin);\n    }\n\n    public static UUID getUUIDFromUserName(String username) {\n        return UUID.nameUUIDFromBytes((\"OfflinePlayer:\" + username).getBytes(UTF_8));\n    }\n\n    public static class AdditionalData {\n        private final UUID uuid;\n        private final Skin skin;\n","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/offline/OfflineAccountFactory.java#L56-L92","documentation":"OfflineAccountFactory.fromStorage throws IllegalStateException when the account's stored metadata JSON lacks the \"profileName\" field. It indicates the persisted account entry is structurally malformed — every offline account must record its profile name in metadata.","triggerScenarios":"Calling fromStorage(metadata, privateData) where metadata (accounts.json entry) has no \"profileName\" key, e.g. after manual edits, partial writes, or downgrades from a different account format.","commonSituations":"Hand-edited or third-party-written accounts.json; crash mid-write truncating the JSON; syncing account files across HMCL versions with differing schemas; importing accounts from other launchers.","solutions":["Restore or add the \"profileName\" field to the account's metadata JSON and reload.","Delete the corrupted offline account entry from accounts.json and re-create the account in the launcher.","Restore accounts.json from backup or re-login all offline accounts."],"exampleFix":"// before (malformed metadata)\n{\"uuid\":\"...\",\"type\":\"offline\"}\n// after\n{\"uuid\":\"...\",\"type\":\"offline\",\"profileName\":\"Steve\",\"profileID\":\"...\"}","handlingStrategy":"try-catch","validationCode":"if (metadata == null || !metadata.has(\"profileName\")) {\n    // treat entry as invalid and skip or recreate it\n    return null;\n}","typeGuard":"boolean isValidOfflineMetadata(JsonObject meta) {\n    return meta != null && meta.has(\"profileName\") && !meta.get(\"profileName\").isJsonNull();\n}","tryCatchPattern":"try {\n    OfflineAccount acc = factory.fromStorage(metadata, privateData);\n} catch (IllegalStateException e) {\n    // remove or rebuild the malformed account entry\n    accountStore.remove(metadata.get(\"uuid\").getAsString());\n}","preventionTips":["Never hand-edit accounts.json; use the launcher's account management.","Back up accounts.json before HMCL version migrations.","Validate stored metadata keys after importing accounts from other tools."],"tags":["json","storage","deserialization"],"backgroundTag":"missing-required-config-field","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"}