{"record":{"id":"772d68fa99ce87c8","repo":"Anuken/Mindustry","slug":"not-a-schematic-file-missing-header","errorCode":null,"errorMessage":"Not a schematic file (missing header).","messagePattern":"Not a schematic file \\(missing header\\)\\.","errorType":"validation","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"core/src/mindustry/game/Schematics.java","lineNumber":573,"sourceCode":"            return read(new ByteArrayInputStream(Base64Coder.decode(schematic.trim())));\n        }catch(IOException e){\n            throw new RuntimeException(e);\n        }\n    }\n\n    public static Schematic read(Fi file) throws IOException{\n        Schematic s = read(new DataInputStream(file.read(1024)));\n        if(!s.tags.containsKey(\"name\")){\n            s.tags.put(\"name\", file.nameWithoutExtension());\n        }\n        s.file = file;\n        return s;\n    }\n\n    public static Schematic read(InputStream input) throws IOException{\n        for(byte b : header){\n            if(input.read() != b){\n                throw new IOException(\"Not a schematic file (missing header).\");\n            }\n        }\n\n        int ver = input.read();\n\n        if(ver > version) throw new IOException(\"Unknown version: \" + ver + \" (are you trying to load a schematic from a newer version of the game?)\");\n\n        try(DataInputStream stream = new DataInputStream(new InflaterInputStream(input))){\n            short width = stream.readShort(), height = stream.readShort();\n\n            if(limitSchematicSize && (width > 128 || height > 128)) throw new IOException(\"Invalid schematic: Too large (max possible size is 128x128)\");\n\n            StringMap map = new StringMap();\n            int tags = stream.readUnsignedByte();\n            for(int i = 0; i < tags; i++){\n                map.put(stream.readUTF(), stream.readUTF());\n            }\n","sourceCodeStart":555,"sourceCodeEnd":591,"githubUrl":"https://github.com/Anuken/Mindustry/blob/f695ad7e60323ebced984fa26d0bcf0bc54296b4/core/src/mindustry/game/Schematics.java#L555-L591","documentation":"Thrown by Schematics.read(InputStream) when the first 4 bytes of the stream do not equal the schematic header bytes {'m','s','c','h'}. The header is a magic-number guard so non-schematic files are rejected before any structured parsing. Any byte mismatch (including EOF returning -1) triggers the throw.","triggerScenarios":"Passing a file/stream to Schematics.read that is not a schematic: wrong file type, a renamed .png/.zip/.msav, a truncated/empty file, or a corrupt schematic. input.read() returning -1 (end of stream) compares != to the header byte and throws.","commonSituations":"User imports the wrong file as a schematic; a schematic file was corrupted by a transfer/sync; reading a schematic tag stored under a different format; pointing read() at a save (.msav) instead of a schematic.","solutions":["Verify the file is a real schematic (first bytes should be 'm','s','c','h').","Check file extension and source; re-export the schematic from a known-good source.","If reading from a network/resource, ensure it isn't truncated (content-length vs actual bytes).","Catch IOException around Schematics.read and report a friendly 'invalid schematic' message to the user."],"exampleFix":"// before\nSchematic s = Schematics.read(file); // may throw on non-schematic\n\n// after\ntry{\n    Schematic s = Schematics.read(file);\n}catch(IOException e){\n    ui.showErrorMessage(\"Not a valid schematic file.\");\n    Log.err(e);\n}","handlingStrategy":"try-catch","validationCode":"// quick header sniff before full parse\ntry(InputStream in = file.read(4)){\n    byte[] magic = {'m','s','c','h'};\n    for(byte b : magic){ if(in.read() != b){ throw new IOException(\"Not a schematic\"); } }\n}","typeGuard":null,"tryCatchPattern":"try{ Schematic s = Schematics.read(file); }catch(IOException e){ ui.showErrorMessage(\"Invalid schematic file\"); Log.err(e); }","preventionTips":["Validate file extension and first bytes before parsing.","Wrap schematic reads in try/catch at the UI boundary.","Keep backups of schematic files to recover from corruption.","Reject obviously wrong file types (png/zip/msav) early."],"tags":["schematic","io","validation","magic-number"],"backgroundTag":null,"analyzedSha":"f695ad7e60323ebced984fa26d0bcf0bc54296b4","analyzedAt":"2026-08-14T04:31:16.262Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}