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
- Re-capture the heap dump and verify the transfer completed (file size/checksum).
- Update Matrix to support the ART/hprof version that produced the dump.
- Check for and fix earlier parse desynchronization (bad idSize, unknown tags) upstream.
- 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
- Verify hprof transfers complete before parsing (size/checksum).
- Keep the parser's hprof version support aligned with target devices.
- Fall back to raw hprof handling when the shrink step throws.
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
- accept class failed, lost type def of typeId:
- Unexpected type for
- visit bmp instance failed, lost type def of typeId:
- visit string instance failed, lost type def of typeId:
- visit instance failed, lost type def of typeId:
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)