You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.base/java.lang.AbstractStringBuilder.setLength(AbstractStringBuilder.java:275)
at java.base/java.lang.StringBuilder.setLength(StringBuilder.java:85)
at com.anypackage.swagger.ApiClient$ApiClientHttpRequestInterceptor.headersToString(ApiClient.java:586)
at com.anypackage.swagger.ApiClient$ApiClientHttpRequestInterceptor.logResponse(ApiClient.java:572)
at com.anypackage.swagger.ApiClient$ApiClientHttpRequestInterceptor.intercept(ApiClient.java:558)
...
It is plain to see that the generated utility method is erroneous in corner cases:
privateStringheadersToString(HttpHeadersheaders) {
StringBuilderbuilder = newStringBuilder();
for (Entry<String, List<String>> entry : headers.entrySet()) {
builder.append(entry.getKey()).append("=[");
for (Stringvalue : entry.getValue()) {
builder.append(value).append(",");
}
builder.setLength(builder.length() - 1); // Get rid of trailing commabuilder.append("],");
}
builder.setLength(builder.length() - 1); // Get rid of trailing commareturnbuilder.toString();
}
Related issues/PRs
None.
Suggest a fix
Return empty string if headers are empty or null.
privateStringheadersToString(HttpHeadersheaders) {
if(headers == null || headers.isEmpty()) {
return"";
}
StringBuilderbuilder = newStringBuilder();
for (Entry<String, List<String>> entry : headers.entrySet()) {
builder.append(entry.getKey()).append("=[");
for (Stringvalue : entry.getValue()) {
builder.append(value).append(",");
}
builder.setLength(builder.length() - 1); // Get rid of trailing commabuilder.append("],");
}
builder.setLength(builder.length() - 1); // Get rid of trailing commareturnbuilder.toString();
}
The text was updated successfully, but these errors were encountered:
Bug Report Checklist
Description
Method
headersToString
throws anStringIndexOutOfBoundsException
in https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache#L844 if givenHttpHeaders
are empty.openapi-generator version
I was using
OpenAPI declaration file content or url
Generation Details
Java, RestTemplate
Steps to reproduce
It is plain to see that the generated utility method is erroneous in corner cases:
Related issues/PRs
None.
Suggest a fix
Return empty string if headers are empty or
null
.The text was updated successfully, but these errors were encountered: