Skip to content

[IO-891] Fix BoundedReader.skip(long) accounting and bounds handling#860

Merged
garydgregory merged 3 commits into
apache:masterfrom
sarankumarbaskar:IO-boundedreader-skip-bounds
Jun 19, 2026
Merged

[IO-891] Fix BoundedReader.skip(long) accounting and bounds handling#860
garydgregory merged 3 commits into
apache:masterfrom
sarankumarbaskar:IO-boundedreader-skip-bounds

Conversation

@sarankumarbaskar

@sarankumarbaskar sarankumarbaskar commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

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:

  • cap skip requests to the remaining bounded range
  • respect mark/readAheadLimit limits
  • update charsRead using the actual skipped count
  • avoid implicit long-to-int narrowing from charsRead += n

Added regression tests for large skip values, bounded skip behavior, actual skipped count, and mark/readAheadLimit behavior.

Fixes: IO-891

  • Read the contribution guidelines for this project.
  • Read the ASF Generative Tooling Guidance.
  • Run a successful build using the default Maven goal with mvn.
  • Wrote unit tests that match the behavioral changes and fail without the runtime fix.
  • Wrote a pull request description explaining what changed and why.
  • Each commit has a meaningful subject line and body.

Limit skip requests to the remaining bound and update charsRead with the actual skipped count.

@garydgregory garydgregory left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sarankumarbaskar
Please see my comments.

@Test
void testSkipRespectsReadAheadLimit() throws IOException {
try (BoundedReader mr = new BoundedReader(new StringReader("01234567890"), 10)) {
mr.mark(3);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sarankumarbaskar sarankumarbaskar Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.
@garydgregory

garydgregory commented Jun 18, 2026

Copy link
Copy Markdown
Member

@sarankumarbaskar
The build is broken.
Always run 'mvn' by itself before you push and fix errors.

@garydgregory

Copy link
Copy Markdown
Member

Jira ticket is IO-891.

@garydgregory garydgregory merged commit e806e6b into apache:master Jun 19, 2026
42 of 45 checks passed
@garydgregory

Copy link
Copy Markdown
Member

I fixed the build, PR merged 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants