Bug Report Checklist
Description
I am using the openapi-generator-cli to generate java code. The generated code throws an assertion error while attempting to deserialize an empty response body coming from a 500 response.
openapi-generator version
7.8.0
OpenAPI declaration file content or url
Generated code will call getApiException when server returns a 500:
try {
HttpResponse<InputStream> localVarResponse = memberVarHttpClient.send(
localVarRequestBuilder.build(),
HttpResponse.BodyHandlers.ofInputStream());
if (memberVarResponseInterceptor != null) {
memberVarResponseInterceptor.accept(localVarResponse);
}
try {
if (localVarResponse.statusCode()/ 100 != 2) {
throw getApiException("something", localVarResponse);
}
The generated code for getApiException is the following:
protected ApiException getApiException(String operationId, HttpResponse<InputStream> response) throws IOException {
String body = response.body() == null ? null : new String(response.body().readAllBytes());
String message = formatExceptionMessage(operationId, response.statusCode(), body);
return new ApiException(response.statusCode(), message, response.headers(), body);
}
The response.body() is not null so the code will attempt to read the bytes of an empty response and trigger an assertion in the underlying int read(byte[] bytes, int off, int len) method:
public int read(byte[] bytes, int off, int len) throws IOException {
...
assert read > 0 && read <= buffer.remaining();
...
}
Generation Details
openapi-generator-cli generate --generator-key=client-java
Steps to reproduce
Create an endpoint that trhows a 500 with a empty body response.
Related issues/PRs
N/A
Suggest a fix
Do not attempt to deserialize the bytes if the response is null not null but empty.
Bug Report Checklist
Description
I am using the
openapi-generator-clito generate java code. The generated code throws an assertion error while attempting to deserialize an empty response body coming from a500response.openapi-generator version
7.8.0OpenAPI declaration file content or url
Generated code will call
getApiExceptionwhen server returns a500:The generated code for
getApiExceptionis the following:The
response.body()is not null so the code will attempt to read the bytes of an empty response and trigger an assertion in the underlyingint read(byte[] bytes, int off, int len)method:Generation Details
openapi-generator-cli generate --generator-key=client-javaSteps to reproduce
Create an endpoint that trhows a 500 with a empty body response.
Related issues/PRs
N/A
Suggest a fix
Do not attempt to deserialize the bytes if the response is null not null but empty.