Tencent/matrix · error · IllegalStateException

accept class failed, lost type def of typeId:

Error message

accept class failed, lost type def of typeId: 

What it means

When processing a CLASS DUMP record's static fields, HprofReader.acceptClassDump() resolves each field's value type via Type.getType(typeId). If the dump contains a static field type byte that is not one of the known hprof types (object/boolean/char/float/double/byte/short/int/long), Type.getType returns null and the reader throws IllegalStateException instead of consuming an unknown-size value from the stream.

Solutions

  1. Re-capture the hprof from the device to replace a corrupted dump.
  2. Confirm the whole file transferred intact (compare checksums between device pull and server copy).
  3. Fix upstream parse errors that may have shifted the stream position before the class dump.
  4. Catch IllegalStateException during parsing and mark the dump invalid.
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, "class dump parse failed; dump may be corrupt", e);
}

Prevention

When it happens

Trigger: acceptClassDump() reads a static field whose type byte is invalid (not 2,4-8) — a corrupted dump or a stream desynchronized by an earlier parse error.

Common situations: Truncated/corrupted hprof transfer off-device; byte-level desynchronization after an earlier unknown tag; hprof post-processed by third-party tools.

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/d933b723ef5cf038. 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:309

        //  Skip over the constant pool
        int numEntries = IOUtil.readBEShort(mStreamIn);
        bytesRead += 2;
        for (int i = 0; i < numEntries; ++i) {
            IOUtil.skip(mStreamIn, 2);
            bytesRead += 2 + skipValue();
        }

        //  Static fields
        numEntries = IOUtil.readBEShort(mStreamIn);
        Field[] staticFields = new Field[numEntries];
        bytesRead += 2;
        for (int i = 0; i < numEntries; ++i) {
            final ID nameId = IOUtil.readID(mStreamIn, mIdSize);
            final int typeId = mStreamIn.read();
            final Type type = Type.getType(typeId);
            if (type == null) {
                throw new IllegalStateException("accept class failed, lost type def of typeId: " + typeId);
            }
            final Object staticValue = IOUtil.readValue(mStreamIn, type, mIdSize);
            staticFields[i] = new Field(typeId, nameId, staticValue);
            bytesRead += mIdSize + 1 + type.getSize(mIdSize);
        }

        //  Instance fields
        numEntries = IOUtil.readBEShort(mStreamIn);
        final Field[] instanceFields = new Field[numEntries];
        bytesRead += 2;
        for (int i = 0; i < numEntries; i++) {
            final ID nameId = IOUtil.readID(mStreamIn, mIdSize);
            final int typeId = mStreamIn.read();
            instanceFields[i] = new Field(typeId, nameId, null);
            bytesRead += mIdSize + 1;
        }

        hdv.visitHeapDumpClass(id, stackSerialNumber, superClassId, classLoaderId, instanceSize, staticFields, instanceFields);

View on GitHub (pinned to 3b8293bd65)