Experiments#819
Conversation
…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)
|
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. |
- ~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
Show autofix suggestion
Hide autofix suggestion
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 (
Mathis injava.lang).
| @@ -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; | ||
| } | ||
| } |
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>
No description provided.