Code example for BufferUnderflowException

0
        if (length < 1) {
            throw new IndexOutOfBoundsException();
        } 
 
        if (bb.remaining() < length) {
            throw new BufferUnderflowException();
        } 
    } 
 
    @Override 
    public byte[] toLexBytes(ClassAndField_IdKey key) throws Exception {
        checkNotNull(key);
        byte[] classNameBytes = key.getClassName().getBytes(UTF8);
        byte[] fieldNameBytes = key.getFieldName().getBytes(UTF8);
        byte[] objectIdBytes = key.getObjectId().toLexBytes().array();
        ByteBuffer bb = ByteBuffer.allocate(4 + classNameBytes.length + 4 + fieldNameBytes.length + objectIdBytes.length);
        bb.putInt(classNameBytes.length);
        bb.put(classNameBytes);
        bb.putInt(fieldNameBytes.length);
        bb.put(fieldNameBytes);