Affects: 6.0.11


The class DefaultDataBuffer has method getNativeBuffer with follow implementation:

    public ByteBuffer getNativeBuffer() {
        this.byteBuffer.position(this.readPosition);
        this.byteBuffer.limit(readableByteCount());
        return this.byteBuffer;
    }

        @Override
    public int readableByteCount() {
        return this.writePosition - this.readPosition;
    }

The limit of the byte buffer to return should be set to the this.writePosition, because if the condition (this.writePosition - this.readPosition) <= this.readPosition is satisfied, the limit of the returned byte buffer will be equal to its current position, so no single byte could be read from this buffer, even if the condition this.writePosition > this.readPosition is satisfied. So how it should be:

    public ByteBuffer getNativeBuffer() {
        return this.byteBuffer.limit(this.writePosition).position(this.readPosition);
    }

Comment From: sbrannen

Thanks for reporting the issue. We'll look into it.

Comment From: injae-kim

I create fix PR https://github.com/spring-projects/spring-framework/pull/32009 with test~! 😃

Comment From: poutsma

You are correct, this is a bug. It does not seem to occur much because the read position is typically 0.

Even though this is a bug fix, it is a breaking change and breaks backward compatibility and therefore I am scheduling it for 6.2.

Comment From: izeye

It seems that this or https://github.com/spring-projects/spring-framework/issues/30967 needs to be superseded not to have two entries for the same in the milestone or the release notes.