[Java][vertx] Apply Vert.x pool defaults in buildWebClient for useVertx5 (#24015)#24017
Merged
wing328 merged 1 commit intoJun 13, 2026
Conversation
…tx5 (OpenAPITools#24015) PoolOptions(JsonObject) does not initialize defaults first, unlike its no-arg constructor and unlike WebClientOptions(JsonObject). The vertx template's two-arg ApiClient constructor delegates with an empty pool config, so buildWebClient built PoolOptions(new JsonObject()), leaving maxLifetimeUnit null (and pool sizes 0). The first API call then threw a NullPointerException from HttpClientImpl via WebClient.create. Overlay poolConfig on the serialized no-arg defaults so absent keys keep their documented values while explicit pool settings still apply. Regenerated the vertx5 and vertx5-supportVertxFuture samples.
Member
|
cc @RickyRister who is the author of #23829 |
Member
|
thanks for the fix, which looks good to me cc @bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @martin-mfg (2023/08) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #24015
Problem
With `library=vertx` and `useVertx5=true`, the generated client throws a `NullPointerException` on the first API call when the `ApiClient` is built with the documented two-arg constructor:
Root cause
The two-arg constructor delegates with an empty pool config, and
buildWebClientturned it intonew PoolOptions(poolConfig). Unlike its no-arg constructor (and unlikeWebClientOptions(JsonObject), which callsinit()first), Vert.x 5'sPoolOptions(JsonObject)constructor does not initialize defaults before applying the JSON. Sonew PoolOptions(new JsonObject())yieldsmaxLifetimeUnit = null(plus pool sizes0), andHttpClientImplNPEs on the null time unit.This path was introduced by #23829 (merged for 7.23.0).
Fix
In
Java/libraries/vertx/ApiClient.mustache, overlaypoolConfigon the serialized no-arg defaults so absent keys keep their documented values while explicit pool settings still apply:PoolOptionsConverteris package-private (@JsonGen(publicConverter = false)), so the overlay goes through the publicPoolOptions.toJson(). This also handles partially-populated pool configs correctly (unlike a simplepoolConfig.isEmpty()guard).Test evidence
Standalone runtime check against
io.vertx:vertx-core:5.0.11:Regenerated the
vertx5andvertx5-supportVertxFuturesamples (bin/generate-samples.sh); both compile (mvn compile, JDK 21). Regenerating the non-vertx5 vertx samples produces no diff (the{{^useVertx5}}branch is unchanged).Verification done
gh pr list --search "vertx PoolOptions"only shows the merged [Java] [vertx] Allow PoolOptions configuration when vertx 5 #23829 that introduced the code; 2. no self-claim comments (0 comments); 3. code-focused (.mustachetemplate + regenerated.java); 4. grepped master —new PoolOptions(poolConfig)still present in template line 734; 5. not a closed sub-issue.Summary by cubic
Fixes #24015: Prevents a NullPointerException on the first API call in Vert.x 5 clients by applying default
PoolOptionsvalues inbuildWebClientwhen the two-argApiClientconstructor is used. Defaults are merged withpoolConfigso missing fields are initialized and user overrides still apply.library=vertxwithuseVertx5=true, avoid NPE caused bynew PoolOptions(poolConfig)when the JSON is empty/partial (Vert.x 5 doesn’t init defaults inPoolOptions(JsonObject)).PoolOptionsvianew PoolOptions().toJson().mergeIn(poolConfig)and pass toWebClient.create(...).useVertx5; regeneratedvertx5samples compile.Written for commit 4e7eaac. Summary will update on new commits.