{"record":{"id":"2689de5c7032ae98","repo":"oracle/graal","slug":"invalid-replay-file-header","errorCode":null,"errorMessage":"Invalid replay file header","messagePattern":"Invalid replay file header","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/BinaryReplayCodec.java","lineNumber":1055,"sourceCode":"        }\n        int size = encodedSize - 1;\n        Map<String, String> properties = new EconomicHashMap<>();\n        for (int i = 0; i < size; i++) {\n            String key = requireNonNullString(readStringReference(in, state), \"property key\");\n            String value = readStringReference(in, state);\n            properties.put(key, value);\n        }\n        return properties;\n    }\n\n    private static void verifyHeader(ObjectCopierInputStream in) throws IOException {\n        for (byte expected : MAGIC) {\n            int actual = in.read();\n            if (actual < 0) {\n                throw new EOFException();\n            }\n            if (actual != Byte.toUnsignedInt(expected)) {\n                throw new IOException(\"Invalid replay file header\");\n            }\n        }\n        int version = in.readPackedUnsignedInt();\n        if (version != VERSION) {\n            throw new IOException(\"Unsupported replay file version \" + version);\n        }\n    }\n\n    private static void writeBooleanFlag(ObjectCopierOutputStream out, boolean value) throws IOException {\n        out.write(value ? 1 : 0);\n    }\n\n    private static boolean readBooleanFlag(ObjectCopierInputStream in) throws IOException {\n        int value = in.read();\n        if (value < 0) {\n            throw new EOFException();\n        }\n        return switch (value) {","sourceCodeStart":1037,"sourceCodeEnd":1073,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/replaycomp/BinaryReplayCodec.java#L1037-L1073","documentation":"verifyHeader reads the MAGIC byte sequence at the start of a replay stream; if any byte differs from the expected constant, it throws IOException 'Invalid replay file header'. This is a deliberate fail-fast check that the input is actually a binary replay file produced by this codec before any parsing begins.","triggerScenarios":"Feeding a text replay file (old replay format), an arbitrary binary, or an empty/truncated file to the binary replay reader; passing a file of a different codec's format.","commonSituations":"Mixing up old textual -XX:+ReplayCompiles output with the new binary format; wrong file passed on the command line; a zero-byte file from a crashed recording run.","solutions":["Confirm the file was produced by the binary replay writer of the same codec","Re-record the replay file if the recording run was interrupted (file may be empty or partial)","Point the replay tool at the correct file path"],"exampleFix":"// before\ntry (var in = new ObjectCopierInputStream(fileIn)) {\n    Object r = readValue(in, state);\n}\n\n// after\nbyte[] head = fileIn.readNBytes(MAGIC.length);\nif (!Arrays.equals(head, MAGIC)) {\n    throw new IOException(\"Not a binary replay file\");\n}","handlingStrategy":"validation","validationCode":"static boolean hasValidMagic(java.io.InputStream in) throws IOException {\n    in.mark(MAGIC.length);\n    boolean ok = true;\n    for (byte expected : MAGIC) {\n        int b = in.read();\n        ok &= b == Byte.toUnsignedInt(expected);\n    }\n    in.reset();\n    return ok;\n}","typeGuard":null,"tryCatchPattern":"try {\n    codec.readReplay(in);\n} catch (IOException e) {\n    if (\"Invalid replay file header\".equals(e.getMessage())) {\n        // wrong file or wrong format: check the path and the recording flags used\n    } else throw e;\n}","preventionTips":["Confirm the file was produced by the binary replay writer, not the older textual replay format","Check the recording process exited cleanly so the file was fully written"],"tags":["graalvm","replay-compilation","header-validation","io","file-format"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}