Tencent/matrix · error · IllegalStateException

failure to skip type, cannot find type def of typeid:

Error message

failure to skip type, cannot find type def of typeid: 

What it means

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.

Solutions

  1. Verify the hprof file is complete and uncorrupted (re-capture the heap dump).
  2. Regenerate the hprof with the standard 'am dumpheap' / Debug.dumpHprofData on a supported Android version instead of third-party dumpers.
  3. Check that earlier parsing steps (header idSize, record offsets) are correct; a wrong idSize desynchronizes the stream and produces bogus type ids.
  4. 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).

Example fix

// before: parsing a truncated file directly
HprofReader reader = new HprofReader(new FileInputStream(partialFile));
reader.read();

// after: validate the file first
File f = new File(path);
if (f.length() < HprofReader.HPROF_HEADER_LENGTH) {
    throw new IOException("hprof file truncated, recapture the dump");
}
HprofReader reader = new HprofReader(new BufferedInputStream(new FileInputStream(f)));
reader.read();
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-parse sanity check
if (file.length() < 32) throw new IOException("hprof too small to be valid");
// header must parse and idSize must be 4 or 8 before trusting record type ids

Type guard

static boolean isKnownTypeId(int id) {
    return Type.getType(id) != null;
}

Try / catch

try {
    reader.read();
} catch (IllegalStateException e) {
    if (e.getMessage().startsWith("failure to skip type")) {
        // treat hprof as corrupt/misaligned: re-capture dump
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08). Data as JSON: /api/errors/e9e38f6c632cc818. 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:383

        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();
        final Type type = Type.getType(typeId);
        if (type == null) {
            throw new IllegalStateException("failure to skip type, cannot find type def of typeid: " + typeId);
        }
        final int size = type.getSize(mIdSize);
        IOUtil.skip(mStreamIn, size);
        return size + 1;
    }
}

View on GitHub (pinned to 3b8293bd65)