OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Java] [resttemplate] HttpServerErrorException is swallowed without logging in ApiClient.java

Open
#17,522 1 comment 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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.