Skip to content

fix [Kotlin]: handle nullable response.body in jvm-okhttp ApiClient t…#23515

Merged
wing328 merged 1 commit intoOpenAPITools:masterfrom
oymo:fix/kotlin-okhttp-nullable-response-body
Apr 13, 2026
Merged

fix [Kotlin]: handle nullable response.body in jvm-okhttp ApiClient t…#23515
wing328 merged 1 commit intoOpenAPITools:masterfrom
oymo:fix/kotlin-okhttp-nullable-response-body

Conversation

@oymo
Copy link
Copy Markdown
Contributor

@oymo oymo commented Apr 10, 2026

One-liner fix of issue 23514, allowing Kotlin 2.x to build generated code.

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.

fixes #23514
This is my first contribution, so any feedback is much appreciated.
@dennisameling, @e5l, @stefankoppier, @yutaka0m, @4brunu, @andrewemery, @Zomzog, @karismann


Summary by cubic

Handle nullable OkHttp response.body in the Kotlin jvm-okhttp ApiClient.responseBody to prevent NPEs and Kotlin 2.x compile errors. Fixes #23514.

  • Bug Fixes
    • In kotlin-client/libraries/jvm-okhttp ApiClient.kt.mustache, return null when response.body is null in responseBody.
    • Regenerated Kotlin jvm-okhttp sample clients to reflect the template change.

Written for commit 5d16e35. Summary will update on new commits.

…emplate

Signed-off-by: Oyvind Mo <oymo76@gmail.com>
Copy link
Copy Markdown
Contributor

@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.

No issues found across 28 files

@oymo
Copy link
Copy Markdown
Contributor Author

oymo commented Apr 10, 2026

Hi maintainers,
The CI failure on node 2 (cpp-restsdk) seems to be unrelated to this PR. It looks like a flaky setup-cpp step when adding the ubuntu-toolchain-r/test PPA (GPG keyserver timeout).
The project is still using an old version of setup-cpp (0.37.0), while 1.8.0+ is available and should handle this better.
See the full log: https://app.circleci.com/pipelines/github/OpenAPITools/openapi-generator/39662/workflows/3880aa81-7094-4f27-a076-d72311590fae/jobs/135141
Would it be possible to bump setup-cpp in CI/circle_parallel.sh (or .circleci/config.yml)?

If anyone can make a PR even for CI maintenance, drop me a note and I'd be happy to give it a go.

@wing328 wing328 merged commit 72fe970 into OpenAPITools:master Apr 13, 2026
68 of 69 checks passed
@wing328
Copy link
Copy Markdown
Member

wing328 commented Apr 13, 2026

thanks for the PR, which has been merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] [kotlin] jvm-okhttp4 ApiClient.kt: response.body used without null-safety — fails to compile with Kotlin 2.x

2 participants