Repository navigation
[Bug] Fix UnsafeByteArrayInputStream to return 0 for zero-length reads at EOF - #16556
Open
siddiqueirshad wants to merge 2 commits into
Open
siddiqueirshad wants to merge 2 commits into
siddiqueirshad wants to merge 2 commits into
Conversation
…s at EOF According to the InputStream.read(byte[], int, int) contract, if len is zero, then 0 should be returned without modifying destination buffers or advancing position, even when the stream is exhausted or empty. Previously, the EOF check ran before the zero-length check, causing read(b, off, 0) and read(new byte[0]) to return -1 at EOF. Handle len == 0 after argument validation and before the EOF check. Add unit tests covering zero-length reads in UnsafeByteArrayInputStreamTest. Fixes apache#16554 Signed-off-by: siddiqui irshad <mohdirshad1306@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 3.3 #16556 +/- ##
============================================
+ Coverage 59.02% 61.01% +1.98%
Complexity 15 15
============================================
Files 1953 1953
Lines 89284 89286 +2
Branches 13477 13478 +1
============================================
+ Hits 52700 54476 +1776
+ Misses 30877 29207 -1670
+ Partials 5707 5603 -104
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
LI123456mo
reviewed
Oct 29, 2026
Author
|
Hi @LI123456mo, thanks for taking a look! Since #16555 covers the comprehensive test suite for both legacy and edge behaviors across the stream reads, I am happy to close this PR in favor of #16555 so efforts remain consolidated. Thanks again for the review! |
Signed-off-by: siddiqueirshad <mohdirshad1306@gmail.com>
Author
|
Updated the test method \ estReadZeroLength()\ to declare \ hrows IOException\ to fix the compilation error across JDK 8/11/17/21/25. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
According to the \InputStream.read(byte[], int, int)\ contract, if \len\ is zero, 0 should be returned without modifying destination buffers or advancing position, even when the stream is exhausted or empty.
Previously, the EOF check ran before the zero-length check in \UnsafeByteArrayInputStream.read(byte[], int, int), causing
ead(b, off, 0)\ and
ead(new byte[0])\ to return -1 at EOF.
This PR:
Fixes #16554