Skip to content

Conversation

@inemtsev
Copy link
Contributor

@inemtsev inemtsev commented Jan 13, 2026

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:

  • Fixes the missing gzip header by applying it after the reset.
  • Increase the size of decompression buffer to 8KB from 512bytes default. 512 bytes is tiny, competing Http clients like OkHttp and Apache use 8KB by default.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

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

    • Initialize gzip after buffer.reset to keep the gzip header in the stream.
  • New Features

    • Stream gzip request bodies via ApiClient.gzipRequestBody and set Content-Encoding/Accept-Encoding headers; enabled via useGzipFeature in config.
    • Use an 8KB GZIPInputStream buffer for response decompression.

Written for commit 0136e92. Summary will update on new commits.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a 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.

}

@Override
public int read(byte[] b, int off, int len) throws IOException {
Copy link

@cubic-dev-ai cubic-dev-ai bot Jan 13, 2026

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) violates InputStream contract by returning -1 on zero-length reads at EOF instead of 0

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/java/native-useGzipFeature/src/main/java/org/openapitools/client/ApiClient.java, line 564:

<comment>read(byte[],off,len) violates InputStream contract by returning -1 on zero-length reads at EOF instead of 0</comment>

<file context>
@@ -478,11 +482,119 @@ public static InputStream getResponseBody(HttpResponse<InputStream> response) th
+    }
+
+    @Override
+    public int read(byte[] b, int off, int len) throws IOException {
+      if (!fillBuffer()) {
+        return -1;
</file context>
Suggested change
public int read(byte[] b, int off, int len) throws IOException {
@Override
public int read(byte[] b, int off, int len) throws IOException {
if (len == 0) {
return 0;
}
if (!fillBuffer()) {
return -1;
}
Fix with Cubic

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.

1 participant