{"record":{"id":"378a3b50ec5d8792","repo":"Tencent/matrix","slug":"visit-instance-failed-lost-type-def-of-typeid","errorCode":null,"errorMessage":"visit instance failed, lost type def of typeId: ","messagePattern":"visit instance failed, lost type def of typeId: ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-resource-canary/matrix-resource-canary-android/src/main/java/com/tencent/matrix/resource/hproflib/HprofBufferShrinker.java","lineNumber":364,"sourceCode":"        HprofBufferShrinkVisitor(HprofWriter hprofWriter) {\n            super(hprofWriter);\n        }\n\n        @Override\n        public HprofHeapDumpVisitor visitHeapDumpRecord(int tag, int timestamp, long length) {\n            return new HprofHeapDumpVisitor(super.visitHeapDumpRecord(tag, timestamp, length)) {\n                @Override\n                public void visitHeapDumpInstance(ID id, int stackId, ID typeId, byte[] instanceData) {\n                    try {\n                        if (typeId.equals(mBmpClassId)) {\n                            ID bufferId = null;\n                            int bufferIdPos = 0;\n                            final ByteArrayInputStream bais = new ByteArrayInputStream(instanceData);\n                            for (Field field : mBmpClassInstanceFields) {\n                                final ID fieldNameStringId = field.nameId;\n                                final Type fieldType = Type.getType(field.typeId);\n                                if (fieldType == null) {\n                                    throw new IllegalStateException(\"visit instance failed, lost type def of typeId: \" + field.typeId);\n                                }\n                                if (mMBufferFieldNameStringId.equals(fieldNameStringId)) {\n                                    bufferId = (ID) IOUtil.readValue(bais, fieldType, mIdSize);\n                                    break;\n                                } else {\n                                    bufferIdPos += IOUtil.skipValue(bais, fieldType, mIdSize);\n                                }\n                            }\n                            if (bufferId != null) {\n                                final ID deduplicatedId = mBmpBufferIdToDeduplicatedIdMap.get(bufferId);\n                                if (deduplicatedId != null && !bufferId.equals(deduplicatedId) && !bufferId.equals(mNullBufferId)) {\n                                    modifyIdInBuffer(instanceData, bufferIdPos, deduplicatedId);\n                                }\n                            }\n                        }\n                    } catch (Throwable thr) {\n                        throw new RuntimeException(thr);\n                    }","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-resource-canary/matrix-resource-canary-android/src/main/java/com/tencent/matrix/resource/hproflib/HprofBufferShrinker.java#L346-L382","documentation":"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.","triggerScenarios":"visitHeapDumpInstance encounters mBmpClassInstanceFields containing a Field whose typeId has no Type definition while scanning for the mBuffer field.","commonSituations":"Truncated or partially written hprof; dumps from a runtime version mismatched with the parser's Type table; hprof files manually converted by other tools.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (hprofFile.length() == 0) {\n    throw new IOException(\"empty hprof: \" + hprofFile);\n}","typeGuard":null,"tryCatchPattern":"try {\n    shrinker.shrink(hprof, out);\n} catch (IllegalStateException e) {\n    Log.e(TAG, \"instance visit failed, keep raw hprof\", e);\n}","preventionTips":["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."],"tags":["android","hprof","memory-analysis","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}