Skip to content

Conversation

@ppkarwasz
Copy link
Contributor

In #790 I introduced IOUtils#checkIndexFromLength calls to validate arguments across the codebase. Ironically, the IOUtils class itself was left out.

This PR addresses that omission by adding argument validation to IOUtils#read and IOUtils#readFully.

Key points:

  • Ensures consistency with the rest of Commons IO by validating offset and length.

  • Fixes inconsistent exception behavior:

    • Previously, length < 0 resulted in an IllegalArgumentException.
    • offset < 0 did not trigger validation and failed later with an IndexOutOfBoundsException.
  • With this change, both invalid cases are handled consistently and upfront.

In #790 I introduced `IOUtils#checkIndexFromLength` calls to validate arguments across the codebase. Ironically, the `IOUtils` class itself was left out.

This PR addresses that omission by adding argument validation to `IOUtils#read` and `IOUtils#readFully`.

Key points:

* Ensures consistency with the rest of Commons IO by validating `offset` and `length`.
* Fixes inconsistent exception behavior:

  * Previously, `length < 0` resulted in an `IllegalArgumentException`.
  * `offset < 0` did not trigger validation and failed later with an `IndexOutOfBoundsException`.
* With this change, both invalid cases are handled consistently and upfront.
@garydgregory garydgregory merged commit 45578a7 into master Oct 3, 2025
21 checks passed
@garydgregory
Copy link
Member

Merged, thank you @ppkarwasz.

@ppkarwasz ppkarwasz deleted the fix/io-utils-read branch October 3, 2025 20:04
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