{"record":{"id":"6034ecb1ce24a36f","repo":"quarkusio/quarkus","slug":"invalid-magic-number-in-aot-cache-file-expected-0","errorCode":null,"errorMessage":"Invalid magic number in AOT cache file: expected 0x${MAGIC} but got 0x${magic}","messagePattern":"Invalid magic number in AOT cache file: expected 0x(.+?) but got 0x(.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"critical","filePath":"independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/AotSerializedApplication.java","lineNumber":158,"sourceCode":"                    data.write(configEntry.content());\n                }\n            }\n            data.flush();\n        }\n    }\n\n    /**\n     * Reads cached resources from an input stream.\n     *\n     * @param in the input stream to read from\n     * @return an AotSerializedApplication containing the main class and cached resources\n     * @throws IOException if an I/O error occurs or the format is invalid\n     */\n    public static AotSerializedApplication read(InputStream in) throws IOException {\n        try (DataInputStream data = new DataInputStream(in)) {\n            int magic = data.readInt();\n            if (magic != MAGIC) {\n                throw new IOException(\"Invalid magic number in AOT cache file: expected 0x\"\n                        + Integer.toHexString(MAGIC) + \" but got 0x\" + Integer.toHexString(magic));\n            }\n\n            int version = data.readInt();\n            if (version != VERSION) {\n                throw new IOException(\"Unsupported AOT cache version: expected \" + VERSION + \" but got \" + version);\n            }\n\n            String mainClass = data.readUTF();\n\n            // Read tracked directories\n            int fullyIndexedDirectoryCount = data.readInt();\n            Set<String> fullyIndexedDirectories = new HashSet<>((int) Math.ceil(fullyIndexedDirectoryCount / 0.75f));\n            for (int i = 0; i < fullyIndexedDirectoryCount; i++) {\n                fullyIndexedDirectories.add(data.readUTF());\n            }\n\n            // Read directory contents","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/AotSerializedApplication.java#L140-L176","documentation":"AotSerializedApplication.read() validates the quarkus-application.dat cache file by reading a 4-byte magic number that must equal MAGIC. A mismatch means the file is not a valid Quarkus AOT cache — it is a different file, truncated, corrupted, or written by an incompatible build — and an IOException is thrown describing both the expected and actual magic values.","triggerScenarios":"Passing an InputStream of a file that is not a Quarkus AOT cache (wrong file at the QUARKUS_APPLICATION_DAT path, partially written/corrupted file, or text/HTML content such as an error page saved where the cache should be).","commonSituations":"Truncated uploads or container layer caches serving a stale/partial quarkus-application.dat, manually replaced cache files, or reading the file from the wrong directory.","solutions":["Rebuild the application with the aot-jar packaging type to regenerate a correct quarkus-application.dat.","Delete the stale/corrupted cache file and re-deploy the full target/quarkus-app directory.","Verify the file being read is actually quarkus-application.dat and not another artifact at the same path."],"exampleFix":"// before\napp = AotSerializedApplication.read(Files.newInputStream(stalePath));\n\n// after: regenerate then read\n// mvn clean package -Dpackaging.type=aot-jar\napp = AotSerializedApplication.read(Files.newInputStream(appRoot.resolve(\"quarkus-application.dat\")));","handlingStrategy":"validation","validationCode":"Path cache = Paths.get(\"target/quarkus-app/quarkus-application.dat\");\ntry (DataInputStream in = new DataInputStream(new BufferedInputStream(Files.newInputStream(cache)))) {\n    int magic = in.readInt();\n    if (magic != 0x51554152 /* expected MAGIC */) throw new IllegalStateException(\"Not a Quarkus AOT cache file\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    app = AotSerializedApplication.read(in);\n} catch (IOException e) {\n    if (e.getMessage().startsWith(\"Invalid magic number\")) {\n        throw new IllegalStateException(\"Corrupt/wrong cache file; rebuild with mvn clean package\", e);\n    } throw e;\n}","preventionTips":["Never hand-edit or replace quarkus-application.dat.","Verify checksums when copying artifacts between environments.","Rebuild cleanly when switching build types."],"tags":["aot","serialization","corruption","startup"],"backgroundTag":"invalid-magic-number","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}