{"record":{"id":"6a0d61a8e1538199","repo":"HMCL-dev/HMCL","slug":"unknown-type-of-file","errorCode":null,"errorMessage":"Unknown type of file ","messagePattern":"Unknown type of file ","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"HMCL/src/main/java/org/jackhuang/hmcl/ui/nbt/NBTEditorPage.java","lineNumber":70,"sourceCode":" * @author Glavo\n */\npublic final class NBTEditorPage extends SpinnerPane implements DecoratorPage {\n    private final ReadOnlyObjectWrapper<State> state;\n    private final Path file;\n    private final NBTFileType type;\n\n    private final BorderPane root = new BorderPane();\n\n    public NBTEditorPage(Path file) throws IOException {\n        getStyleClass().add(\"gray-background\");\n\n        this.state = new ReadOnlyObjectWrapper<>(State.fromTitle(i18n(\"nbt.title\", file.toString())));\n        this.file = file;\n\n        //noinspection DataFlowIssue\n        this.type = NBTFileType.ofFile(file);\n        if (type == null) {\n            throw new IOException(\"Unknown type of file \" + file);\n        }\n\n        setContent(root);\n        setLoading(true);\n\n        HBox actions = new HBox(8);\n        actions.setPadding(new Insets(8));\n        actions.setAlignment(Pos.CENTER_RIGHT);\n\n        JFXButton saveButton = FXUtils.newRaisedButton(i18n(\"button.save\"));\n        saveButton.setOnAction(e -> {\n            try {\n                save();\n            } catch (IOException ex) {\n                LOG.warning(\"Failed to save NBT file\", ex);\n                Controllers.dialog(i18n(\"nbt.save.failed\") + \"\\n\\n\" + StringUtils.getStackTrace(ex));\n            }\n        });","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCL/src/main/java/org/jackhuang/hmcl/ui/nbt/NBTEditorPage.java#L52-L88","documentation":"The NBT editor page determines how to parse a file via NBTFileType.ofFile(file); if no known NBT file type matches, the constructor throws IOException(\"Unknown type of file \" + file). HMCL only supports structured NBT formats (region files, level.dat, player data, etc.), so arbitrary binary or non-NBT files are rejected at page creation.","triggerScenarios":"Opening a file in HMCL's NBT editor whose signature does not match any registered NBTFileType — e.g. a plain text file, a log file, a zip that is not a recognized NBT container, or corrupted data whose magic bytes were lost.","commonSituations":"Dragging a random file into the editor; opening a modpack config that is not NBT; edited/corrupted level.dat losing its gzip magic; opening newer save formats an old HMCL version does not recognize.","solutions":["Verify the file is actually an NBT file (level.dat, .mca region, player .dat, etc.)","Update HMCL if the file uses a newer save format","Restore the file from backup if it is corrupted (magic bytes missing)","Use a dedicated NBT tool (e.g. NBTExplorer) or unzip the file if it is a container"],"exampleFix":"// before\nthis.type = NBTFileType.ofFile(file);\nif (type == null) {\n    throw new IOException(\"Unknown type of file \" + file);\n}\n// after\n// caller-side guard\nbyte[] head = new byte[4];\ntry (InputStream in = Files.newInputStream(file)) { in.readNBytes(head, 0, 4); }\nif (!NBTFileType.sniffSupported(head))\n    Controllers.dialog(\"Not a supported NBT file: \" + file, ...);","handlingStrategy":"validation","validationCode":"boolean looksLikeNbt(Path file) throws IOException {\n    byte[] head = new byte[2];\n    try (InputStream in = Files.newInputStream(file)) {\n        if (in.readNBytes(head, 0, 2) != 2) return false;\n    }\n    return (head[0] & 0xFF) == 0x1F && (head[1] & 0xFF) == 0x8B   // gzip NBT\n        || (head[0] & 0xFF) == 0x0A                                 // uncompressed NBT TAG_Compound\n        || file.toString().endsWith(\".mca\") || file.toString().endsWith(\".mcr\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    openNbtEditor(file);\n} catch (IOException e) {\n    if (e.getMessage().startsWith(\"Unknown type of file\")) {\n        Controllers.dialog(\"This file is not a supported NBT format\");\n    } else throw e;\n}","preventionTips":["Only open known NBT files (level.dat, .dat player data, .mca region files)","Update HMCL when Minecraft introduces new save formats","Check gzip/NBT magic bytes (1F 8B or 0x0A) before opening","Keep backups of save files before editing"],"tags":["nbt","file-format","validation","minecraft"],"backgroundTag":"unsupported-operation","analyzedSha":"24702dc5a0214034f4c27166d5fd30cad08cec19","analyzedAt":"2026-09-10T12:36:46.680Z","contentChangedAt":"2026-09-10T12:36:46.680Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}