Skip to content

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

@vlavasa

Description

@vlavasa

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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions