Bug Report
Description
For the Java client generator with library=apache-httpclient, ApiClient.setConnectTimeout(int) silently does nothing. It stores the value into a connectionTimeout field, but that field is never read anywhere else in the generated class — it's never used to build a RequestConfig/ConnectionConfig, and it's never applied to the already-constructed CloseableHttpClient.
This means any consumer who calls apiClient.setConnectTimeout(600) expecting a 600ms connect timeout gets no timeout enforcement at all — the client silently falls back to whatever HttpClients.createDefault() uses internally (Apache HttpClient5's own default connect timeout, currently 3 minutes, with no response/socket timeout at all).
openapi-generator version
7.14.0 (confirmed the same dead code still exists on master as of this report, in modules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/ApiClient.mustache)
generator config
<generatorName>java</generatorName>
<configOptions>
<library>apache-httpclient</library>
...
</configOptions>
Root cause
In the generated ApiClient.java:
public ApiClient() {
this(HttpClients.createDefault()); // httpClient built immediately, with Apache defaults
}
...
protected int connectionTimeout = 0;
...
public ApiClient setConnectTimeout(int connectionTimeout) {
this.connectionTimeout = connectionTimeout; // stored, never read again
return this;
}
Grepping the whole generated file for connectionTimeout shows it's only referenced by the field declaration, the getter, and the setter — never in the request-building/execution path (ClassicRequestBuilder, HttpClientContext, or the httpClient.execute(...) call), and never used to construct a RequestConfig or ConnectionConfig that gets attached to the httpClient.
Expected behavior
Calling setConnectTimeout(ms) should actually bound the TCP connect time for subsequent requests, consistent with how the setter behaves for the other Java libraries:
- okhttp-gson:
httpClient = httpClient.newBuilder().connectTimeout(ms, TimeUnit.MILLISECONDS).build(); — rebuilds the client with the timeout applied.
- native (
java.net.http): this.builder.connectTimeout(connectTimeout); — applied directly to the HttpClient.Builder.
Only apache-httpclient has a setter that looks functional (matching method signature/Javadoc) but is actually a no-op.
Suggested fix
In ApiClient.mustache for apache-httpclient, wire connectionTimeout (and ideally add symmetric support for response/socket timeout, which also has no default) into a PoolingHttpClientConnectionManager + ConnectionConfig/RequestConfig, and rebuild httpClient when setConnectTimeout is called — mirroring the approach used in the okhttp-gson template.
Impact
Anyone relying on apache-httpclient's setConnectTimeout() for production timeout/resiliency behavior gets unbounded (3-minute connect / infinite response) timeouts instead.
Bug Report
Description
For the Java client generator with
library=apache-httpclient,ApiClient.setConnectTimeout(int)silently does nothing. It stores the value into aconnectionTimeoutfield, but that field is never read anywhere else in the generated class — it's never used to build aRequestConfig/ConnectionConfig, and it's never applied to the already-constructedCloseableHttpClient.This means any consumer who calls
apiClient.setConnectTimeout(600)expecting a 600ms connect timeout gets no timeout enforcement at all — the client silently falls back to whateverHttpClients.createDefault()uses internally (Apache HttpClient5's own default connect timeout, currently 3 minutes, with no response/socket timeout at all).openapi-generator version
7.14.0 (confirmed the same dead code still exists on
masteras of this report, inmodules/openapi-generator/src/main/resources/Java/libraries/apache-httpclient/ApiClient.mustache)generator config
Root cause
In the generated
ApiClient.java:Grepping the whole generated file for
connectionTimeoutshows it's only referenced by the field declaration, the getter, and the setter — never in the request-building/execution path (ClassicRequestBuilder,HttpClientContext, or thehttpClient.execute(...)call), and never used to construct aRequestConfigorConnectionConfigthat gets attached to thehttpClient.Expected behavior
Calling
setConnectTimeout(ms)should actually bound the TCP connect time for subsequent requests, consistent with how the setter behaves for the other Java libraries:httpClient = httpClient.newBuilder().connectTimeout(ms, TimeUnit.MILLISECONDS).build();— rebuilds the client with the timeout applied.java.net.http):this.builder.connectTimeout(connectTimeout);— applied directly to theHttpClient.Builder.Only
apache-httpclienthas a setter that looks functional (matching method signature/Javadoc) but is actually a no-op.Suggested fix
In
ApiClient.mustacheforapache-httpclient, wireconnectionTimeout(and ideally add symmetric support for response/socket timeout, which also has no default) into aPoolingHttpClientConnectionManager+ConnectionConfig/RequestConfig, and rebuildhttpClientwhensetConnectTimeoutis called — mirroring the approach used in theokhttp-gsontemplate.Impact
Anyone relying on
apache-httpclient'ssetConnectTimeout()for production timeout/resiliency behavior gets unbounded (3-minute connect / infinite response) timeouts instead.