Skip to content
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

[BUG] Resteasy Response object not closed after API call #13327

Closed
2 of 6 tasks
MikeEdgar opened this issue Aug 31, 2022 · 1 comment · Fixed by #13333
Closed
2 of 6 tasks

[BUG] Resteasy Response object not closed after API call #13327

MikeEdgar opened this issue Aug 31, 2022 · 1 comment · Fixed by #13333

Comments

@MikeEdgar
Copy link
Contributor

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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

Resteasy client template does not close the Response (implements AutoCloseable).

Response response = null;
if ("GET".equals(method)) {
response = invocationBuilder.get();
} else if ("POST".equals(method)) {
response = invocationBuilder.post(entity);
} else if ("PUT".equals(method)) {
response = invocationBuilder.put(entity);
} else if ("DELETE".equals(method)) {
response = invocationBuilder.method("DELETE", entity);
} else if ("PATCH".equals(method)) {
response = invocationBuilder.method("PATCH", entity);
} else if ("HEAD".equals(method)) {
response = invocationBuilder.head();
} else if ("OPTIONS".equals(method)) {
response = invocationBuilder.options();
} else if ("TRACE".equals(method)) {
response = invocationBuilder.trace();
} else {
throw new ApiException(500, "unknown method type " + method);
}
statusCode = response.getStatusInfo().getStatusCode();
responseHeaders = buildResponseHeaders(response);
if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) {
return null;
} else if (response.getStatusInfo().getFamily().equals(Status.Family.SUCCESSFUL)) {
if (returnType == null)
return null;
else
return deserialize(response, returnType);
} else {
String message = "error";
String respBody = null;
if (response.hasEntity()) {
try {
respBody = String.valueOf(response.readEntity(String.class));
message = respBody;
} catch (RuntimeException e) {
// e.printStackTrace();
}
}
throw new ApiException(
response.getStatus(),
message,
buildResponseHeaders(response),
respBody);
}

openapi-generator version

6.0.1

OpenAPI declaration file content or url

N/A

Generation Details

N/A

Steps to reproduce

N/A

Related issues/PRs

N/A

Suggest a fix

Handle the Response using try-with-resources, such as: https://github.com/MikeEdgar/openapi-generator/blob/06e93fabbfd66cd4f0f26d47bfba32a9ce3992d4/modules/openapi-generator/src/main/resources/Java/libraries/resteasy/ApiClient.mustache#L675-L730

@MikeEdgar MikeEdgar changed the title [BUG] Description [BUG] Resteasy Response object not closed after API call Aug 31, 2022
@wing328
Copy link
Member

wing328 commented Sep 1, 2022

@MikeEdgar thanks for reporting the issue. Can you please file a PR with the suggested change?

MikeEdgar added a commit to MikeEdgar/app-services-sdk-java that referenced this issue Sep 1, 2022
wtrocki pushed a commit to redhat-developer/app-services-sdk-java that referenced this issue Sep 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants