OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Java] [resttemplate] HttpServerErrorException is swallowed without logging in ApiClient.java
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Hallo,
in upgrade from OpenApiGenerator version 7.1.0 to version 7.2.0
this change took place in the code generation of the ApiClient.java class in Java / Restemplate generator:
Old code:
ResponseEntity<T> responseEntity = restTemplate.exchange(requestEntity, returnType);
New code:
ResponseEntity<T> responseEntity = null;
int attempts = 0;
while (attempts < maxAttemptsForRetry) {
try {
responseEntity = restTemplate.exchange(requestEntity, returnType);
break;
} catch (HttpServerErrorException ex) {
attempts++;
if (attempts < maxAttemptsForRetry) {
try {
Thread.sleep(waitTimeMillis);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
}
if (responseEntity == null) {
throw new RestClientException("API returned HttpServerErrorException");
}
See:
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache
line: 771 ~ 789
It is a commendable attempt to implement a retry mechanism.
But it brings an unwanted side effect. Catched HttpServerErrorException is swallowed without any log of cause!!! So nobody know if there was problem, how many attempts was done! And it makes almost impossible to find the issue, why communication failed at all!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache around lines 771-789 and inspect the retry loop. Confirm the generated ApiClient preserves the caught HttpServerErrorException cause and records how many attempts occurred, then verify the resulting failure behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100