-
Notifications
You must be signed in to change notification settings - Fork 303
SeekableInMemoryByteChannel.position(long) shouldn't throw an IllegalArgumentException for a new positive position that's too large #756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
IllegalArgumentException for a new positive position that's too large
|
This is related to #754 and @ppkarwasz 's comment there. |
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
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| position += wanted; | ||
| if (size < position) { | ||
| size = position; | ||
| final int intPos2 = (int) position; | ||
| if (size < intPos2) { | ||
| size = intPos2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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;There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
IllegalArgumentException for a new positive position that's too large #756
| if (newSize < 0) { // overflow | ||
| resize(Integer.MAX_VALUE); | ||
| wanted = Integer.MAX_VALUE - position; | ||
| wanted = Integer.MAX_VALUE - intPos; | ||
| } else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
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.