{"record":{"id":"41f8c342337af2ac","repo":"HMCL-dev/HMCL","slug":"pack-cannot-be-null","errorCode":null,"errorMessage":"pack cannot be null","messagePattern":"pack cannot be null","errorType":"validation","errorClass":"JsonParseException","httpStatus":null,"severity":"error","filePath":"HMCLCore/src/main/java/org/jackhuang/hmcl/addon/meta/PackMcMeta.java","lineNumber":64,"sourceCode":"        PackMcMeta parsed = LENIENT_GSON.fromJson(jsonString, PackMcMeta.class);\n        if (parsed == null)\n            throw new JsonParseException(\"Json object cannot be null.\");\n        return parsed;\n    }\n\n    public static PackMcMeta fromNonNullJsonFile(Path jsonFile) throws JsonParseException, IOException {\n        try (var reader = Files.newBufferedReader(jsonFile)) {\n            PackMcMeta parsed = LENIENT_GSON.fromJson(reader, PackMcMeta.class);\n            if (parsed == null)\n                throw new JsonParseException(\"Json object cannot be null.\");\n            return parsed;\n        }\n    }\n\n    @Override\n    public void validate() throws JsonParseException {\n        if (pack == null)\n            throw new JsonParseException(\"pack cannot be null\");\n    }\n\n    @JsonAdapter(PackInfoDeserializer.class)\n    public record PackInfo(@SerializedName(\"pack_format\") int packFormat,\n                           @SerializedName(\"supported_formats\") SupportedFormats supportedFormats,\n                           @SerializedName(\"min_format\") PackVersion minPackVersion,\n                           @SerializedName(\"max_format\") PackVersion maxPackVersion,\n                           @SerializedName(\"description\") LocalAddonFile.Description description) {\n        public PackVersion getEffectiveMinVersion() {\n            return !minPackVersion.isUnspecified() ? minPackVersion : new PackVersion(packFormat, 0);\n        }\n\n        public PackVersion getEffectiveMaxVersion() {\n            return !maxPackVersion.isUnspecified() ? maxPackVersion : new PackVersion(packFormat, 0);\n        }\n    }\n\n    public record SupportedFormats(int min, int max) {","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCLCore/src/main/java/org/jackhuang/hmcl/addon/meta/PackMcMeta.java#L46-L82","documentation":"PackMcMeta.validate() enforces the model's contract that the `pack` field is present. If the parsed JSON lacked a `pack` object (or it failed its custom deserializer), validation throws JsonParseException with this message.","triggerScenarios":"Calling packMcMeta.validate() after parsing a pack.mcmeta with no `pack` key, or after constructing PackMcMeta without pack.","commonSituations":"Resource packs missing the required `pack` section; typos like `Pack` or `pack_format` at the wrong nesting level; new-format pack.mcmeta rejected by the PackInfoDeserializer.","solutions":["Add a valid `pack` object to pack.mcmeta","Check key spelling and nesting (`{\"pack\": {\"pack_format\": N, \"description\": \"...\"}}`)","Verify pack_format/supported_formats values are accepted by the deserializer"],"exampleFix":"// before\n{ \"pack_format\": 15, \"description\": \"oops\" }\n// after\n{ \"pack\": { \"pack_format\": 15, \"description\": \"My pack\" } }","handlingStrategy":"try-catch","validationCode":"JsonObject root = JsonParser.parseString(Files.readString(path)).getAsJsonObject();\nif (!root.has(\"pack\")) throw new IllegalStateException(\"missing 'pack' section\");","typeGuard":null,"tryCatchPattern":"try {\n    PackMcMeta.fromNonNullJsonFile(path).validate();\n} catch (JsonParseException e) {\n    log.warn(\"pack.mcmeta failed validation: \" + e.getMessage());\n}","preventionTips":["Always include {\"pack\": {\"pack_format\": N, \"description\": \"...\"}}","Watch key casing and nesting","Call validate() immediately after parsing to fail fast"],"tags":["java","validation","pack-mcmeta","schema"],"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"}