fix: respect read limit in BoundedInputStream.available()#779
Merged
garydgregory merged 9 commits intomasterfrom Sep 8, 2025
Merged
fix: respect read limit in BoundedInputStream.available()#779garydgregory merged 9 commits intomasterfrom
garydgregory merged 9 commits intomasterfrom
Conversation
`BoundedInputStream.getRemaining()` previously returned `0` when no read limit was set, which was misleading. It now returns `Long.MAX_VALUE` to more clearly represent an unbounded stream. The Javadoc was also updated to clarify that the method reflects only the configured limit and does **not** report the actual number of bytes available in the underlying stream.
`BoundedInputStream.available()` previously returned the underlying stream’s availability without applying the configured read limit. It now caps the reported value by the remaining bytes allowed by the bound. Additional changes: * Removed the `onMaxLength` call from `available()`, since `available()` does not consume data and cannot exceed the maximum count. * Reworked the `testAvailableAfterClose` and `testReadAfterClose` tests: * Old versions relied too heavily on `CharSequenceInputStream`’s specific behavior. * New parameterized tests cover all three typical cases of the underlying stream after close: no-op, return special value, or throw an exception. * Added a dedicated unit test for the corrected `available()` behavior.
garydgregory
requested changes
Sep 5, 2025
Member
garydgregory
left a comment
There was a problem hiding this comment.
Hello @ppkarwasz
Good bug fix! 😄 I have comments scattered throughout.
src/main/java/org/apache/commons/io/input/BoundedInputStream.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/commons/io/input/BoundedInputStream.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/commons/io/input/BoundedInputStream.java
Outdated
Show resolved
Hide resolved
src/test/java/org/apache/commons/io/input/BoundedInputStreamTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/apache/commons/io/input/BoundedInputStreamTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/apache/commons/io/input/BoundedInputStreamTest.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/commons/io/input/BoundedInputStream.java
Outdated
Show resolved
Hide resolved
5 tasks
Member
|
Merged, thank you @ppkarwasz. |
8 tasks
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.
Note
This PR depends on the fixes proposed in #778. It should not be marked as ready for review until that PR has been approved or rejected.
BoundedInputStream.available()previously returned the underlying stream’s availability without applying the configured read limit. It now caps the reported value by the remaining bytes allowed by the bound.Additional changes:
Removed the
onMaxLengthcall fromavailable(), sinceavailable()does not consume data and cannot exceed the maximum count.Reworked the
testAvailableAfterCloseandtestReadAfterClosetests:CharSequenceInputStream’s specific behavior.Added a dedicated unit test for the corrected
available()behavior.Before you push a pull request, review this list:
mvn; that'smvnon the command line by itself.