quarkusio/quarkus · critical · RuntimeException

Wrong magic number

Error message

Wrong magic number

What it means

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).

Source

Thrown at independent-projects/bootstrap/runner/src/main/java/io/quarkus/bootstrap/runner/SerializedApplication.java:135

                data.writeUTF(p.replace('/', '.').replace('\\', '.'));
            }

            data.writeShort(fullyIndexedResourcesToCPJarIndex.size());
            for (Map.Entry<String, List<Integer>> entry : fullyIndexedResourcesToCPJarIndex.entrySet()) {
                data.writeUTF(entry.getKey());
                data.writeShort(entry.getValue().size());
                for (Integer index : entry.getValue()) {
                    data.writeShort(index);
                }
            }
            data.flush();
        }
    }

    public static SerializedApplication read(InputStream inputStream, Path appRoot) throws IOException {
        try (DataInputStream in = new DataInputStream(inputStream)) {
            if (in.readInt() != MAGIC) {
                throw new RuntimeException("Wrong magic number");
            }
            if (in.readInt() != VERSION) {
                throw new RuntimeException("Wrong class path version");
            }
            String mainClass = in.readUTF();
            ResourceDirectoryTracker resourceDirectoryTracker = new ResourceDirectoryTracker();
            int numPaths = in.readUnsignedShort();
            ClassLoadingResource[] allClassLoadingResources = new ClassLoadingResource[numPaths];
            ClassLoadingResource generatedBytecodeClassLoadingResource = null;
            Set<String> generatedBytecode = Set.of();
            ClassLoadingResource transformedBytecodeClassLoadingResource = null;
            Set<String> transformedBytecode = Set.of();
            for (int pathCount = 0; pathCount < numPaths; pathCount++) {
                String path = in.readUTF();
                boolean hasManifest = in.readBoolean();
                ManifestInfo info = null;
                if (hasManifest) {
                    info = new ManifestInfo(readNullableString(in), readNullableString(in), readNullableString(in),

View on GitHub (pinned to e1c734241f)

Solutions

  1. Regenerate the serialized application image with a matching Quarkus version (mvn clean package).
  2. Verify the file is the correct artifact (check first bytes with xxd should show the magic value) and non-empty.
  3. Confirm build and runtime Quarkus versions match; mixed versions break the format contract.
  4. Restore the correct image if it was overwritten or replaced by another file.

Example fix

// before
head -c 4 app.dat  # shows 'PK\x03\x04' — wrong file (a jar)
// after
mvn clean package && xxd -l 4 target/*.dat  # verify magic, then redeploy
Defensive patterns

Strategy: validation

Validate before calling

byte[] head = new byte[4];
try (var in = new java.io.DataInputStream(Files.newInputStream(img))) { in.readFully(head); }
if (java.nio.ByteBuffer.wrap(head).getInt() != expectedMagic) throw new IllegalStateException("wrong image file: " + img);

Type guard

boolean hasQuarkusMagic(Path p) throws IOException { try (var in = new java.io.DataInputStream(Files.newInputStream(p))) { return in.readInt() == expectedMagic; } }

Try / catch

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; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/7c45edbeb20988fc. Report an issue: GitHub.