@Test
    public void testParsingMalformedMessageTypeVarint() {
        MetadataRecordSerde serde = new MetadataRecordSerde();
        ByteBuffer buffer = ByteBuffer.allocate(64);
        buffer.clear();
        buffer.put((byte) 0x01);
        buffer.put((byte) 0x80);
        buffer.put((byte) 0x80);
        buffer.put((byte) 0x80);
        buffer.put((byte) 0x80);
        buffer.put((byte) 0x80);
        buffer.put((byte) 0x80);
        buffer.position(0);
        buffer.limit(64);
        assertStartsWith("Error while reading type",
                assertThrows(MetadataParseException.class,
                        () -> serde.read(new ByteBufferAccessor(buffer), buffer.remaining())).getMessage());
    }
Test attempting to parse an event which has a malformed message type varint.
metadata/src/test/java/org/apache/kafka/metadata/MetadataRecordSerdeTest.java