allthingssecurity opened a new pull request, #27859: URL: https://github.com/apache/camel/pull/27859
# Description [CAMEL-25656](https://issues.apache.org/jira/browse/CAMEL-25656) Follow-up of the review of #27757 ([CAMEL-25573](https://issues.apache.org/jira/browse/CAMEL-25573)), where it was suggested as optional. `NettyChannelBufferStreamCache` holds the whole request body in a `ByteBuf` but did not override `InputStream.available()`, so it always returned 0. `available()` now returns `buffer.readableBytes()`: the bytes that can still be read without blocking (the same value as `length()`), 0 at the end, and the whole length again after `reset()`. Camel's own copies of this stream are not affected: the two-argument `IOHelper.copy`, which this class's `writeTo` and the type converters use, goes through `transferTo` and does not call `available()`. Only the `IOHelper.copy` overloads that take a buffer size read `available()`, and their only caller in core (`CachedOutputStream`) passes its own cache, not this stream. Tests: - New test `availableIsTheNumberOfBytesLeft` in `NettyChannelBufferStreamCacheTest`: a body of 5 bytes in a buffer of capacity 16; `available()` before and after reads, at the end, and after `reset()`. Without the change it fails: `expected: <5> but was: <0>`. - camel-netty-http with the change: 313 tests, 0 failures, 8 skipped. No upgrade-guide note: a reader cannot rely on `available()` returning 0, the `InputStream` contract allows any number of bytes that can be read without blocking. What was not run: only the camel-netty-http tests, with JDK 21. The `GZIPInputStream` case named in the review was not tested: in the sources of JDK 21.0.11, `GZIPInputStream` does not call `available()` (checked in the sources of JDK 17.0.19 and 21.0.11). # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [ ] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it). (The ticket is drafted and not filed yet; CAMEL-25656 is a placeholder until it is.) # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. (I built and tested camel-netty-http, including the formatter and import-sort plugins. I did not run the full root build.) # AI-assisted contributions - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used. This PR was prepared with Claude Code (Claude Opus 5.5). The commit carries a `Co-Authored-By` trailer. _Claude Code on behalf of allthingssecurity_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
