Skip to content

FastByteArrayOutputStream$FastByteArrayInputStream behaves incorrectly when no data is available [SPR-13858] #18431

@spring-projects-issues

Description

@spring-projects-issues

Cornelius Riemenschneider opened SPR-13858 and commented

The read(byte[] b, int off, int len) method of FastByteArrayOutputStream$FastByteArrayInputStream returns 0 instead of -1 in the condition of this.currentBuffer == null.
The correct return value would be -1, as the read() method already does.
This breaks for example StreamUtils.copy(), which never leaves the loop.

The issue is fixed by replacing
if (this.currentBuffer == null) {
// this stream doesn't have any data in it
return 0;
}

with
if (this.currentBuffer == null) {
// this stream doesn't have any data in it
return -1;
}


Affects: 4.2.4

Referenced from: commits 5d4547d, 8516de6

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