-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
[Java][Native] Fix request compression #22688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 issue found across 4 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="samples/client/petstore/java/native-useGzipFeature/src/main/java/org/openapitools/client/ApiClient.java">
<violation number="1" location="samples/client/petstore/java/native-useGzipFeature/src/main/java/org/openapitools/client/ApiClient.java:564">
P2: read(byte[],off,len) violates InputStream contract by returning -1 on zero-length reads at EOF instead of 0</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
...ent/petstore/java/native-useGzipFeature/src/main/java/org/openapitools/client/ApiClient.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 issue found across 4 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="modules/openapi-generator/src/main/resources/Java/libraries/native/ApiClient.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/native/ApiClient.mustache:573">
P2: read(byte[],off,len) now returns 0 for len==0 without null/bounds validation, diverging from InputStream contract and masking invalid arguments</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| if (len == 0) { | ||
| return 0; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: read(byte[],off,len) now returns 0 for len==0 without null/bounds validation, diverging from InputStream contract and masking invalid arguments
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/Java/libraries/native/ApiClient.mustache, line 573:
<comment>read(byte[],off,len) now returns 0 for len==0 without null/bounds validation, diverging from InputStream contract and masking invalid arguments</comment>
<file context>
@@ -570,6 +570,9 @@ public class ApiClient {
@Override
public int read(byte[] b, int off, int len) throws IOException {
+ if (len == 0) {
+ return 0;
+ }
</file context>
| if (len == 0) { | |
| return 0; | |
| } | |
| Objects.requireNonNull(b, "buffer must not be null"); | |
| if (off < 0 || len < 0 || len > b.length - off) { | |
| throw new IndexOutOfBoundsException(); | |
| } | |
| if (len == 0) { | |
| return 0; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion, I have fixed this edge-case
|
Ready to go from my side. |
|
@inemtsev thanks for the PR may I confirm with you that you've tested this change (the latest one after incorporating feedback from cubic-dev-ai) locally to confirm it works for your use cases? |
During testing of the newly added Gzip feature for Java+native template, we discovered that request was missing the gzip header in the stream because it was being cleared by the buffer.reset() method. This PR:
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)Summary by cubic
Fixes gzip request compression in the Java native client so the gzip header is preserved. Also enables streaming gzip for requests and uses an 8KB buffer for response decompression.
Bug Fixes
New Features
Written for commit 6293788. Summary will update on new commits.