{"record":{"id":"7c45edbeb20988fc","repo":"quarkusio/quarkus","slug":"wrong-magic-number","errorCode":null,"errorMessage":"Wrong magic number","messagePattern":"Wrong magic number","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/SerializedApplication.java","lineNumber":135,"sourceCode":"                data.writeUTF(p.replace('/', '.').replace('\\\\', '.'));\n            }\n\n            data.writeShort(fullyIndexedResourcesToCPJarIndex.size());\n            for (Map.Entry<String, List<Integer>> entry : fullyIndexedResourcesToCPJarIndex.entrySet()) {\n                data.writeUTF(entry.getKey());\n                data.writeShort(entry.getValue().size());\n                for (Integer index : entry.getValue()) {\n                    data.writeShort(index);\n                }\n            }\n            data.flush();\n        }\n    }\n\n    public static SerializedApplication read(InputStream inputStream, Path appRoot) throws IOException {\n        try (DataInputStream in = new DataInputStream(inputStream)) {\n            if (in.readInt() != MAGIC) {\n                throw new RuntimeException(\"Wrong magic number\");\n            }\n            if (in.readInt() != VERSION) {\n                throw new RuntimeException(\"Wrong class path version\");\n            }\n            String mainClass = in.readUTF();\n            ResourceDirectoryTracker resourceDirectoryTracker = new ResourceDirectoryTracker();\n            int numPaths = in.readUnsignedShort();\n            ClassLoadingResource[] allClassLoadingResources = new ClassLoadingResource[numPaths];\n            ClassLoadingResource generatedBytecodeClassLoadingResource = null;\n            Set<String> generatedBytecode = Set.of();\n            ClassLoadingResource transformedBytecodeClassLoadingResource = null;\n            Set<String> transformedBytecode = Set.of();\n            for (int pathCount = 0; pathCount < numPaths; pathCount++) {\n                String path = in.readUTF();\n                boolean hasManifest = in.readBoolean();\n                ManifestInfo info = null;\n                if (hasManifest) {\n                    info = new ManifestInfo(readNullableString(in), readNullableString(in), readNullableString(in),","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/SerializedApplication.java#L117-L153","documentation":"A RuntimeException from SerializedApplication.read when the first int of the serialized application stream does not equal the expected MAGIC constant. The file being deserialized is not a Quarkus serialized application image (or is from an incompatible/garbage file).","triggerScenarios":"Reading the serialized application at startup: the input stream's first 4 bytes are not MAGIC — pointing at a wrong, empty, overwritten, or non-image file.","commonSituations":"Deployed the wrong artifact (e.g. a jar or properties file where the .dat image belongs); image truncated to 0 or few bytes; older/newer Quarkus build wrote a different format header; placeholder file committed in place of the real image.","solutions":["Regenerate the serialized application image with a matching Quarkus version (mvn clean package).","Verify the file is the correct artifact (check first bytes with xxd should show the magic value) and non-empty.","Confirm build and runtime Quarkus versions match; mixed versions break the format contract.","Restore the correct image if it was overwritten or replaced by another file."],"exampleFix":"// before\nhead -c 4 app.dat  # shows 'PK\\x03\\x04' — wrong file (a jar)\n// after\nmvn clean package && xxd -l 4 target/*.dat  # verify magic, then redeploy","handlingStrategy":"validation","validationCode":"byte[] head = new byte[4];\ntry (var in = new java.io.DataInputStream(Files.newInputStream(img))) { in.readFully(head); }\nif (java.nio.ByteBuffer.wrap(head).getInt() != expectedMagic) throw new IllegalStateException(\"wrong image file: \" + img);","typeGuard":"boolean hasQuarkusMagic(Path p) throws IOException { try (var in = new java.io.DataInputStream(Files.newInputStream(p))) { return in.readInt() == expectedMagic; } }","tryCatchPattern":"try { app.start(); } catch (RuntimeException e) { if (\"Wrong magic number\".equals(e.getMessage())) { log.error(\"Serialized app image invalid — regenerate with matching Quarkus version\", e); throw new IllegalStateException(\"Redeploy correct .dat image\", e); } throw e; }","preventionTips":["Rebuild the image whenever the Quarkus version changes.","Verify artifacts (magic/checksum) before deployment.","Deploy complete artifact directories, never individual substituted files.","Add a startup smoke test that validates the image header."],"tags":["deserialization","format","startup"],"backgroundTag":"bad-magic-number","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}