{"record":{"id":"904ef7f89a7cb086","repo":"HMCL-dev/HMCL","slug":"type-must-between-0-s","errorCode":null,"errorMessage":"Type must between [0, %s)","messagePattern":"Type must between \\[0, (.+?)\\)","errorType":"validation","errorClass":"JsonParseException","httpStatus":null,"severity":"error","filePath":"HMCL/src/main/java/org/jackhuang/hmcl/terracotta/TerracottaState.java","lineNumber":301,"sourceCode":"            HOST_ET_CRASH,\n            PING_SERVER_RST,\n            SCAFFOLDING_INVALID_RESPONSE\n        }\n\n        private static final TerracottaState.Exception.Type[] LOOKUP = Type.values();\n\n        @SerializedName(\"type\")\n        private final int type;\n\n        Exception(int port, int index, String state, int type) {\n            super(port, index, state);\n            this.type = type;\n        }\n\n        @Override\n        public void validate() throws JsonParseException, TolerableValidationException {\n            if (type < 0 || type >= LOOKUP.length) {\n                throw new JsonParseException(String.format(\"Type must between [0, %s)\", LOOKUP.length));\n            }\n        }\n\n        public Type getType() {\n            return LOOKUP[type];\n        }\n    }\n\n    public static final class Fatal extends TerracottaState {\n        public enum Type {\n            OS,\n            NETWORK,\n            INSTALL,\n            TERRACOTTA,\n            UNKNOWN;\n        }\n\n        private final Type type;","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCL/src/main/java/org/jackhuang/hmcl/terracotta/TerracottaState.java#L283-L319","documentation":"TerracottaState's typed entry validates that its integer 'type' field indexes into the LOOKUP table (0 <= type < LOOKUP.length). An out-of-range type would otherwise throw ArrayIndexOutOfBoundsException later, so JsonParseException with the allowed range is thrown during validation.","triggerScenarios":"A state/type entry whose type is negative or >= LOOKUP.length — produced by a newer HMCL version with more types, or corrupted/hand-edited JSON.","commonSituations":"Downgrading HMCL so newer type ids are unrecognized; manual edits inserting wrong ids; data corruption.","solutions":["Set type to a value within [0, LOOKUP.length) as defined by this HMCL build","Upgrade HMCL to a version whose LOOKUP table includes the declared type","Fix or regenerate the state file instead of hand-editing type ids","Catch JsonParseException and reset the entry to a known-valid type"],"exampleFix":"// before\n\"type\": 9\n// after\n\"type\": 0","handlingStrategy":"validation","validationCode":"int t = entry.get(\"type\").getAsInt(); if (t < 0 || t >= TerracottaState.LOOKUP.length) { throw new IllegalArgumentException(\"type \" + t + \" out of range\"); }","typeGuard":"static boolean knownType(int t) { return t >= 0 && t < TerracottaState.LOOKUP.length; }","tryCatchPattern":"try { entry.validate(); } catch (JsonParseException e) { LOG.warning(\"Invalid terracotta type id; resetting\", e); }","preventionTips":["Map unknown ids to defaults when loading files from other versions","Upgrade rather than downgrade HMCL when type ids advance","Document valid type id range in config tooling"],"tags":["json","validation","range"],"backgroundTag":"value-out-of-range","analyzedSha":"24702dc5a0214034f4c27166d5fd30cad08cec19","analyzedAt":"2026-09-10T12:36:46.680Z","contentChangedAt":"2026-09-10T12:36:46.680Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}