Bug Report Checklist
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 (f99cf3b) but compilation failed for some apparently unrelated reason: missing Enum.java. (Bisected this to #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+.
Bug Report Checklist
Description
I noticed that the
XxxApi.javafile generated when usinglibrary=nativecallsapiClient.getHttpClient()and stores the resultingHttpClientin aprivatefield, but never calls.close()on it. (This class was madeAutoCloseablein 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 specialHttpClient.Builderwhich tracked all the times.build()was called, and retain weak references so they could be closed later.openapi-generator version
openapi-generator-maven-pluginversion7.25.0OpenAPI 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.javaExpected: some call to
memberVarHttpClient.close(). Actual: none, just created and then used to make requests.NOTE: I tried to reproduce in trunk (f99cf3b) but compilation failed for some apparently unrelated reason: missing
Enum.java. (Bisected this to #24812.)OriginServiceApi.javawas still generated the same way, still compilable, still missing.close().Related issues/PRs
(none found)
Suggest a fix
Whatever template change would effect
when configured for Java 21+.