Skip to content

Experiments#819

Draft
garydgregory wants to merge 328 commits into
fix/read-onlyfrom
master
Draft

Experiments#819
garydgregory wants to merge 328 commits into
fix/read-onlyfrom
master

Conversation

@garydgregory
Copy link
Copy Markdown
Member

No description provided.

garydgregory and others added 24 commits November 23, 2025 09:16
…an IllegalArgumentException for a new positive position that's too large (#817)

* [IO-856] Try test on all OSs for GitHub CI

* ByteArraySeekableByteChannel.position|truncate(long) shouldn't throw an
IllegalArgumentException for a new positive position that's too large

* Throw IOException instead of OutOfMemoryError

* Refactor internals for safer and less type casting
…an IllegalArgumentException for a new positive position that's too large #817
* [IO-856] Try test on all OSs for GitHub CI

* Add and use IOUtils.closeQuietly(Closeable, Throwable)
@github-advanced-security
Copy link
Copy Markdown

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

@garydgregory garydgregory marked this pull request as draft December 14, 2025 15:29
- ~2.6x speedup on StringReader input
- ~10% speed on file resource as InputStreamReader

Benchmark
Mode  Cnt          Score         Error  Units
IOUtilsContentEqualsReadersBenchmark_2_22_0.testFileCurrent
avgt    5     105274.452 ±    1466.048  ns/op
IOUtilsContentEqualsReadersBenchmark_2_22_0.testFileRelease2_22_0
avgt    5     107500.847 ±    1752.422  ns/op
IOUtilsContentEqualsReadersBenchmark_2_22_0.testFile_2_21_0
avgt    5     115720.416 ±    1209.652  ns/op
IOUtilsContentEqualsReadersBenchmark_2_22_0.testStringCurrent
avgt    5  113330719.330 ± 1187191.151  ns/op
IOUtilsContentEqualsReadersBenchmark_2_22_0.testStringRelease2_22_0
avgt    5  110389392.582 ±  785367.455  ns/op
IOUtilsContentEqualsReadersBenchmark_2_22_0.testString_2_21_0
avgt    5  284939866.619 ± 9969793.485  ns/op

Apache Maven 3.9.12 (848fbb4bf2d427b72bdb2471c22fced7ebd9a7a1)
Maven home: /opt/homebrew/Cellar/maven/3.9.12/libexec
Java version: 21.0.9, vendor: Homebrew, runtime:
/opt/homebrew/Cellar/openjdk@21/21.0.9/libexec/openjdk.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "26.2", arch: "aarch64", family: "mac"

@Override
public long skip(final long n) throws IOException {
charsRead += n;

Check failure

Code scanning / CodeQL

Implicit narrowing conversion in compound assignment High

Implicit cast of source type long to narrower destination type
int
.

Copilot Autofix

AI about 1 month ago

To fix this without changing intended behavior, avoid compound assignment between int and long. Compute the actual skipped amount from the underlying reader first, then update charsRead using a checked conversion from long to int.

Best fix in this file:

  • In skip(long n), replace:
    • charsRead += n;
    • return super.skip(n);
  • With:
    • final long skipped = super.skip(n);
    • charsRead = Math.addExact(charsRead, Math.toIntExact(skipped));
    • return skipped;

Why this is best:

  • Removes implicit narrowing conversion.
  • Tracks real skipped count (more accurate than adding requested n).
  • Fails fast with clear arithmetic exception on impossible overflow/truncation instead of silent corruption.
  • Requires no new imports (Math is in java.lang).
Suggested changeset 1
src/main/java/org/apache/commons/io/input/BoundedReader.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/main/java/org/apache/commons/io/input/BoundedReader.java b/src/main/java/org/apache/commons/io/input/BoundedReader.java
--- a/src/main/java/org/apache/commons/io/input/BoundedReader.java
+++ b/src/main/java/org/apache/commons/io/input/BoundedReader.java
@@ -132,7 +132,8 @@
 
     @Override
     public long skip(final long n) throws IOException {
-        charsRead += n;
-        return super.skip(n);
+        final long skipped = super.skip(n);
+        charsRead = Math.addExact(charsRead, Math.toIntExact(skipped));
+        return skipped;
     }
 }
EOF
@@ -132,7 +132,8 @@

@Override
public long skip(final long n) throws IOException {
charsRead += n;
return super.skip(n);
final long skipped = super.skip(n);
charsRead = Math.addExact(charsRead, Math.toIntExact(skipped));
return skipped;
}
}
Copilot is powered by AI and may make mistakes. Always verify output.
garydgregory and others added 24 commits April 19, 2026 11:39
Bumps org.apache.commons:commons-parent from 99 to 100.

---
updated-dependencies:
- dependency-name: org.apache.commons:commons-parent
  dependency-version: '100'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.

7 participants