Tencent/matrix · error · IllegalStateException

accept primitive array failed, lost type def of typeId:

Error message

accept primitive array failed, lost type def of typeId: 

What it means

HprofReader.acceptPrimitiveArrayDump() reads a primitive array record's element type byte and resolves it via Type.getType(typeId) to compute element size. An unknown type byte yields a null Type, and the reader throws IllegalStateException because it cannot determine how many bytes of element data to read.

Solutions

  1. Re-capture the heap dump and verify the transfer completed (file size/checksum).
  2. Update Matrix to support the ART/hprof version that produced the dump.
  3. Check for and fix earlier parse desynchronization (bad idSize, unknown tags) upstream.
  4. Catch IllegalStateException and fall back to handling the raw hprof without the shrink step.
Defensive patterns

Strategy: try-catch

Validate before calling

if (file.length() == 0 || !file.canRead()) {
    throw new IOException("hprof missing or unreadable");
}

Try / catch

try {
    hprofReader.accept(visitor);
} catch (IllegalStateException e) {
    Log.e(TAG, "primitive array parse failed; dump may be corrupt", e);
}

Prevention

When it happens

Trigger: acceptPrimitiveArrayDump() encounters a PRIMITIVE ARRAY DUMP record whose type byte is not a valid hprof primitive type — corrupted dump or a stream desynchronized by earlier mis-parsing.

Common situations: Truncated hprof after interrupted device pull; parser mismatch with newer ART dump format; stream misalignment from an earlier bad record length.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08). Data as JSON: /api/errors/029a731d57a876f8. Report an issue: GitHub.

Appendix: source

Thrown at matrix/matrix-android/matrix-resource-canary/matrix-resource-canary-android/src/main/java/com/tencent/matrix/resource/hproflib/HprofReader.java:362

        final ID id = IOUtil.readID(mStreamIn, mIdSize);
        final int stackId = IOUtil.readBEInt(mStreamIn);
        final int numElements = IOUtil.readBEInt(mStreamIn);
        final ID typeId = IOUtil.readID(mStreamIn, mIdSize);
        final int remaining = numElements * mIdSize;
        final byte[] elements = new byte[remaining];
        IOUtil.readFully(mStreamIn, elements, 0, remaining);
        hdv.visitHeapDumpObjectArray(id, stackId, numElements, typeId, elements);
        return mIdSize + 4 + 4 + mIdSize + remaining;
    }

    private int acceptPrimitiveArrayDump(int tag, HprofHeapDumpVisitor hdv) throws IOException {
        final ID id = IOUtil.readID(mStreamIn, mIdSize);
        final int stackId = IOUtil.readBEInt(mStreamIn);
        final int numElements = IOUtil.readBEInt(mStreamIn);
        final int typeId = mStreamIn.read();
        final Type type = Type.getType(typeId);
        if (type == null) {
            throw new IllegalStateException("accept primitive array failed, lost type def of typeId: " + typeId);
        }
        final int remaining = numElements * type.getSize(mIdSize);
        final byte[] elements = new byte[remaining];
        IOUtil.readFully(mStreamIn, elements, 0, remaining);
        hdv.visitHeapDumpPrimitiveArray(tag, id, stackId, numElements, typeId, elements);
        return mIdSize + 4 + 4 + 1 + remaining;
    }

    private int acceptJniMonitor(HprofHeapDumpVisitor hdv) throws IOException {
        final ID id = IOUtil.readID(mStreamIn, mIdSize);
        final int threadSerialNumber = IOUtil.readBEInt(mStreamIn);
        final int stackDepth = IOUtil.readBEInt(mStreamIn);
        hdv.visitHeapDumpJniMonitor(id, threadSerialNumber, stackDepth);
        return mIdSize + 4 + 4;
    }

    private int skipValue() throws IOException {
        final int typeId = mStreamIn.read();

View on GitHub (pinned to 3b8293bd65)