Tencent/matrix · error · IllegalStateException
visit instance failed, lost type def of typeId:
Error message
visit instance failed, lost type def of typeId:
What it means
In the general instance-visiting path, HprofBufferShrinker again resolves each Bitmap class field type via Type.getType(field.typeId) to skip fields until it reaches mBuffer. A null Type means the dump has no definition for that typeId, so the parser cannot compute the field size (skipValue) and throws IllegalStateException to avoid misparsing the binary stream.
Solutions
- Re-capture the heap dump to replace a corrupted file.
- Align the Matrix version with the device/runtime that produced the hprof.
- Pre-validate the hprof structure (e.g. parse the class dump section independently) before shrinking.
- Handle IllegalStateException during parse and fall back to uploading the raw hprof.
Defensive patterns
Strategy: try-catch
Validate before calling
if (hprofFile.length() == 0) {
throw new IOException("empty hprof: " + hprofFile);
} Try / catch
try {
shrinker.shrink(hprof, out);
} catch (IllegalStateException e) {
Log.e(TAG, "instance visit failed, keep raw hprof", e);
} Prevention
- Avoid post-processing hprof files with third-party tools before Matrix parses them.
- Re-capture corrupted dumps instead of retrying.
- Match parser Type tables to the device ART version.
When it happens
Trigger: visitHeapDumpInstance encounters mBmpClassInstanceFields containing a Field whose typeId has no Type definition while scanning for the mBuffer field.
Common situations: Truncated or partially written hprof; dumps from a runtime version mismatched with the parser's Type table; hprof files manually converted by other 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
- visit bmp instance failed, lost type def of typeId:
- visit string instance failed, lost type def of typeId:
- Unexpected type for
- accept class failed, lost type def of typeId:
- accept primitive array failed, lost type def of typeId:
AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08).
Data as JSON: /api/errors/378a3b50ec5d8792.
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/HprofBufferShrinker.java:364
HprofBufferShrinkVisitor(HprofWriter hprofWriter) {
super(hprofWriter);
}
@Override
public HprofHeapDumpVisitor visitHeapDumpRecord(int tag, int timestamp, long length) {
return new HprofHeapDumpVisitor(super.visitHeapDumpRecord(tag, timestamp, length)) {
@Override
public void visitHeapDumpInstance(ID id, int stackId, ID typeId, byte[] instanceData) {
try {
if (typeId.equals(mBmpClassId)) {
ID bufferId = null;
int bufferIdPos = 0;
final ByteArrayInputStream bais = new ByteArrayInputStream(instanceData);
for (Field field : mBmpClassInstanceFields) {
final ID fieldNameStringId = field.nameId;
final Type fieldType = Type.getType(field.typeId);
if (fieldType == null) {
throw new IllegalStateException("visit instance failed, lost type def of typeId: " + field.typeId);
}
if (mMBufferFieldNameStringId.equals(fieldNameStringId)) {
bufferId = (ID) IOUtil.readValue(bais, fieldType, mIdSize);
break;
} else {
bufferIdPos += IOUtil.skipValue(bais, fieldType, mIdSize);
}
}
if (bufferId != null) {
final ID deduplicatedId = mBmpBufferIdToDeduplicatedIdMap.get(bufferId);
if (deduplicatedId != null && !bufferId.equals(deduplicatedId) && !bufferId.equals(mNullBufferId)) {
modifyIdInBuffer(instanceData, bufferIdPos, deduplicatedId);
}
}
}
} catch (Throwable thr) {
throw new RuntimeException(thr);
}View on GitHub (pinned to 3b8293bd65)