Skip to content

The method getNativeBuffer() in DefaultDataBuffer returns misconfigured ByteBuffer #30967

@access-control-rtfm

Description

@access-control-rtfm

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);
	}

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions