[IO-891] Fix BoundedReader.skip(long) accounting and bounds handling#860
Conversation
Limit skip requests to the remaining bound and update charsRead with the actual skipped count.
garydgregory
left a comment
There was a problem hiding this comment.
@sarankumarbaskar
Please see my comments.
| @Test | ||
| void testSkipRespectsReadAheadLimit() throws IOException { | ||
| try (BoundedReader mr = new BoundedReader(new StringReader("01234567890"), 10)) { | ||
| mr.mark(3); |
There was a problem hiding this comment.
Hello @sarankumarbaskar
I don't think you understand what mark is supposed to do. Please read the docs and see if there's a real issue once you fix these new tests.
There was a problem hiding this comment.
@garydgregory Thanks, I see your point. Before changing this further, I want to clarify the intended behavior.
Should BoundedReader.skip(long) respect only maxCharsFromTargetReader, or should it also honor the active mark/readAheadLimit the same way read() currently does?
I can keep this PR limited to the clear issue — capping skip() to maxCharsFromTargetReader and updating charsRead with the actual skipped count — unless you think skip() should also mirror the readAheadLimit check.
There was a problem hiding this comment.
Please review the contract of the mark and reset methods and notice the word "attempt". You're trying to turn override one feature (reading) with another (mark/reset).
Unless you can provide a strong argument that marking should act as a hard limit, I don't see a use case here.
There was a problem hiding this comment.
@garydgregory Thanks, that clarifies it. I removed the mark/readAheadLimit-specific logic and test. The PR is now limited to skip(long) respecting maxCharsFromTargetReader and updating charsRead with the actual skipped count returned by the delegate.
Keep skip(long) focused on maxCharsFromTargetReader and actual skipped count, without treating mark read-ahead as a hard limit.
|
@sarankumarbaskar |
|
Jira ticket is IO-891. |
|
I fixed the build, PR merged 🚀 |
BoundedReader.skip(long) was updating charsRead using the requested skip amount instead of the actual number of characters skipped by the underlying reader.
This could make the reader lose track of its bounded position when the delegate skipped fewer characters than requested. It also allowed skip requests to go past maxCharsFromTargetReader, while read() correctly stops at the configured bound.
This PR updates skip(long) to:
Added regression tests for large skip values, bounded skip behavior, actual skipped count, and mark/readAheadLimit behavior.
Fixes: IO-891
mvn.