SeekableInMemoryByteChannel.position(long) shouldn't throw an IllegalArgumentException for a new positive position that's too large#756
Merged
garydgregory merged 3 commits intoapache:masterfrom Dec 8, 2025
Conversation
IllegalArgumentException for a new positive position that's too large
Draft
7 tasks
Member
Author
|
This is related to #754 and @ppkarwasz 's comment there. |
ppkarwasz
requested changes
Dec 8, 2025
src/main/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannel.java
Outdated
Show resolved
Hide resolved
src/test/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannelTest.java
Outdated
Show resolved
Hide resolved
SeekableByteChannel and WritableByteChannel Javadoc better
ppkarwasz
approved these changes
Dec 8, 2025
Comment on lines
197
to
200
| position += wanted; | ||
| if (size < position) { | ||
| size = position; | ||
| final int intPos2 = (int) position; | ||
| if (size < intPos2) { | ||
| size = intPos2; |
Contributor
There was a problem hiding this comment.
Nit: What about reusing intPos? Also a comment might be useful to explain that intPos + wanted is at most (Integer.MAX_VALUE - intPos) + intPos.
position = intPos += wanted;
if (size < intPos) {
size = intPos;
garydgregory
added a commit
that referenced
this pull request
Dec 8, 2025
IllegalArgumentException for a new positive position that's too large #756
ppkarwasz
reviewed
Dec 8, 2025
Comment on lines
190
to
193
| if (newSize < 0) { // overflow | ||
| resize(Integer.MAX_VALUE); | ||
| wanted = Integer.MAX_VALUE - position; | ||
| wanted = Integer.MAX_VALUE - intPos; | ||
| } else { |
Contributor
There was a problem hiding this comment.
I didn't catch it before, because I didn't have the Javadoc in mind, however the generic WritableByteChannel#write Javadoc says:
Unless otherwise specified, a write operation will return only after writing all of the
rrequested bytes.
So this edge case should throw instead of decreasing wanted. Do you agree?
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.
SeekableInMemoryByteChannel.position(long) shouldn't throw an IllegalArgumentException for a new positive position that's too large
Before you push a pull request, review this list:
mvn; that'smvnon the command line by itself.