Skip to content

Core: Fix ByteBufferInputStream.read() to return -1 at EOF#16167

Open
sachinnn99 wants to merge 1 commit intoapache:mainfrom
sachinnn99:fix/16127-bytebufferinputstream-read-eof
Open

Core: Fix ByteBufferInputStream.read() to return -1 at EOF#16167
sachinnn99 wants to merge 1 commit intoapache:mainfrom
sachinnn99:fix/16127-bytebufferinputstream-read-eof

Conversation

@sachinnn99
Copy link
Copy Markdown
Contributor

Fixes #16127.

SingleBufferInputStream.read() and MultiBufferInputStream.read() throw EOFException when the stream is exhausted. This violates the java.io.InputStream contract, which requires the no-arg read() to return -1 at EOF.

The multi-byte read(byte[], int, int) in both classes already correctly returns -1 at EOF — the two overloads were inconsistent.

Changes:

  • SingleBufferInputStream.read(): return -1 instead of throwing EOFException
  • MultiBufferInputStream.read(): return -1 at both EOF entry points instead of throwing EOFException
  • Update testReadByte() to assert -1 return (including idempotency check)

Other EOFException-throwing methods (slice(), sliceBuffers(), skipFully()) are unchanged — they request specific byte counts where EOFException is the correct signal.

@github-actions github-actions Bot added the core label Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ByteBufferInputStream.read() throws EOFException at EOF instead of returning -1, violating InputStream contract

1 participant