OpenAPITools / OpenAPITools/openapi-generator

[BUG] [JAVA] `HttpClient memberVarHttpClient` not `close`d

Open
#24,942 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I noticed that the XxxApi.java file generated when using library=native calls apiClient.getHttpClient() and stores the resulting HttpClient in a private field, but never calls .close() on it. (This class was made AutoCloseable in Java 21, and closing it is important to release resources.) Clients of the library could not easily work around this; they would have to pass in a special HttpClient.Builder which tracked all the times .build() was called, and retain weak references so they could be closed later.

openapi-generator version

openapi-generator-maven-plugin version 7.25.0

OpenAPI declaration file content or url

(see steps to reproduce)

Generation Details

(see steps to reproduce)

Steps to reproduce
git clone https://github.com/jenkinsci/cursor-origin-branch-source-plugin .
git checkout 2b2e1c5beaac428488aa5406e0d38721a572d57b
mvn -Pquick-build package
fgrep memberVarHttpClient target/generated-sources/openapi/io/jenkins/plugins/cursor_origin_branch_source/origin_openapi/api/OriginServiceApi.java

Expected: some call to memberVarHttpClient.close(). Actual: none, just created and then used to make requests.

NOTE: I tried to reproduce in trunk (f99cf3bbbbb9c5eee56f4298a667db0c326d40ee) but compilation failed for some apparently unrelated reason: missing Enum.java. (Bisected this to https://github.com/OpenAPITools/openapi-generator/pull/24812.) OriginServiceApi.java was still generated the same way, still compilable, still missing .close().

Related issues/PRs

(none found)

Suggest a fix

Whatever template change would effect

116,116c116,116
< public class OriginServiceApi {
---
> public class OriginServiceApi implements AutoCloseable {
158a159,162
>   @Override
>   public void close() {
>      memberVarHttpClient.close();
>   }

when configured for Java 21+.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the generated OriginServiceApi.java output from the documented Maven reproduction and trace it back to the Java native-library generator template. Check how Java 21+ configuration is represented before deciding where the AutoCloseable behavior belongs. Done means generated clients close memberVarHttpClient and the relevant generation or compilation checks pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.