{"record":{"id":"e9e38f6c632cc818","repo":"Tencent/matrix","slug":"failure-to-skip-type-cannot-find-type-def-of-type","errorCode":null,"errorMessage":"failure to skip type, cannot find type def of typeid: ","messagePattern":"failure to skip type, cannot find 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/HprofReader.java","lineNumber":383,"sourceCode":"        final byte[] elements = new byte[remaining];\n        IOUtil.readFully(mStreamIn, elements, 0, remaining);\n        hdv.visitHeapDumpPrimitiveArray(tag, id, stackId, numElements, typeId, elements);\n        return mIdSize + 4 + 4 + 1 + remaining;\n    }\n\n    private int acceptJniMonitor(HprofHeapDumpVisitor hdv) throws IOException {\n        final ID id = IOUtil.readID(mStreamIn, mIdSize);\n        final int threadSerialNumber = IOUtil.readBEInt(mStreamIn);\n        final int stackDepth = IOUtil.readBEInt(mStreamIn);\n        hdv.visitHeapDumpJniMonitor(id, threadSerialNumber, stackDepth);\n        return mIdSize + 4 + 4;\n    }\n\n    private int skipValue() throws IOException {\n        final int typeId = mStreamIn.read();\n        final Type type = Type.getType(typeId);\n        if (type == null) {\n            throw new IllegalStateException(\"failure to skip type, cannot find type def of typeid: \" + typeId);\n        }\n        final int size = type.getSize(mIdSize);\n        IOUtil.skip(mStreamIn, size);\n        return size + 1;\n    }\n}\n","sourceCodeStart":365,"sourceCodeEnd":390,"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/HprofReader.java#L365-L390","documentation":"HprofReader.skipValue() reads a type identifier byte from the hprof stream and looks it up in the Type enum. When the byte does not correspond to any known hprof basic type (object, boolean, char, float, double, byte, short, int, long), the reader cannot know how many bytes the value occupies and throws this IllegalStateException. It almost always means the parser has lost synchronization with the hprof file structure.","triggerScenarios":"Parsing a corrupt or truncated hprof file; parsing an hprof written by a non-standard or newer JVM/Android ART version that emits type ids this library does not know; calling HprofReader APIs at a wrong byte offset so a non-type byte is interpreted as a type id.","commonSituations":"Memory leak analysis of hprof files pulled from devices with a different ART version than the one the library was built for; partially transferred/downloaded hprof files; manually patched or filtered hprof files whose records were re-serialized incorrectly.","solutions":["Verify the hprof file is complete and uncorrupted (re-capture the heap dump).","Regenerate the hprof with the standard 'am dumpheap' / Debug.dumpHprofData on a supported Android version instead of third-party dumpers.","Check that earlier parsing steps (header idSize, record offsets) are correct; a wrong idSize desynchronizes the stream and produces bogus type ids.","If a custom dumper was used, ensure value types are written with the standard hprof basic-type tags (2,4,5,6,7,8,9,10,11)."],"exampleFix":"// before: parsing a truncated file directly\nHprofReader reader = new HprofReader(new FileInputStream(partialFile));\nreader.read();\n\n// after: validate the file first\nFile f = new File(path);\nif (f.length() < HprofReader.HPROF_HEADER_LENGTH) {\n    throw new IOException(\"hprof file truncated, recapture the dump\");\n}\nHprofReader reader = new HprofReader(new BufferedInputStream(new FileInputStream(f)));\nreader.read();","handlingStrategy":"try-catch","validationCode":"// pre-parse sanity check\nif (file.length() < 32) throw new IOException(\"hprof too small to be valid\");\n// header must parse and idSize must be 4 or 8 before trusting record type ids","typeGuard":"static boolean isKnownTypeId(int id) {\n    return Type.getType(id) != null;\n}","tryCatchPattern":"try {\n    reader.read();\n} catch (IllegalStateException e) {\n    if (e.getMessage().startsWith(\"failure to skip type\")) {\n        // treat hprof as corrupt/misaligned: re-capture dump\n    }\n}","preventionTips":["Only parse hprof files captured by supported Android versions","Verify file completeness (size, header) before parsing","Always parse from the file start so offsets stay aligned"],"tags":["hprof","parsing","android","memory-analysis"],"backgroundTag":"invalid-enum-value","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"}