Skip to content

Commit 6e30ad0

Browse files
authored
[Java][vertx] Apply Vert.x pool defaults in buildWebClient for useVertx5 (#24015) (#24017)
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.
1 parent 1cfe9bf commit 6e30ad0

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

  • modules/openapi-generator/src/main/resources/Java/libraries/vertx
  • samples/client/petstore/java

modules/openapi-generator/src/main/resources/Java/libraries/vertx/ApiClient.mustache

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,19 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
731731
config.put("userAgent", "{{{httpUserAgent}}}{{^httpUserAgent}}OpenAPI-Generator/{{{artifactVersion}}}/java{{/httpUserAgent}}");
732732
}
733733

734-
return WebClient.create(vertx, new WebClientOptions(config){{#useVertx5}}, new PoolOptions(poolConfig){{/useVertx5}});
734+
{{#useVertx5}}
735+
// PoolOptions(JsonObject) does not initialize defaults first (unlike its
736+
// no-arg constructor and unlike WebClientOptions(JsonObject)), so building
737+
// it directly from an empty or partial poolConfig leaves fields such as
738+
// maxLifetimeUnit null and triggers a NullPointerException when the
739+
// WebClient is created. Overlay poolConfig on the serialized defaults so
740+
// absent keys keep their documented values.
741+
PoolOptions poolOptions = new PoolOptions(new PoolOptions().toJson().mergeIn(poolConfig));
742+
return WebClient.create(vertx, new WebClientOptions(config), poolOptions);
743+
{{/useVertx5}}
744+
{{^useVertx5}}
745+
return WebClient.create(vertx, new WebClientOptions(config));
746+
{{/useVertx5}}
735747
}
736748

737749

samples/client/petstore/java/vertx5-supportVertxFuture/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,14 @@ protected WebClient buildWebClient(Vertx vertx, JsonObject config, JsonObject po
664664
config.put("userAgent", "OpenAPI-Generator/1.0.0/java");
665665
}
666666

667-
return WebClient.create(vertx, new WebClientOptions(config), new PoolOptions(poolConfig));
667+
// PoolOptions(JsonObject) does not initialize defaults first (unlike its
668+
// no-arg constructor and unlike WebClientOptions(JsonObject)), so building
669+
// it directly from an empty or partial poolConfig leaves fields such as
670+
// maxLifetimeUnit null and triggers a NullPointerException when the
671+
// WebClient is created. Overlay poolConfig on the serialized defaults so
672+
// absent keys keep their documented values.
673+
PoolOptions poolOptions = new PoolOptions(new PoolOptions().toJson().mergeIn(poolConfig));
674+
return WebClient.create(vertx, new WebClientOptions(config), poolOptions);
668675
}
669676

670677

samples/client/petstore/java/vertx5/src/main/java/org/openapitools/client/ApiClient.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,14 @@ protected WebClient buildWebClient(Vertx vertx, JsonObject config, JsonObject po
664664
config.put("userAgent", "OpenAPI-Generator/1.0.0/java");
665665
}
666666

667-
return WebClient.create(vertx, new WebClientOptions(config), new PoolOptions(poolConfig));
667+
// PoolOptions(JsonObject) does not initialize defaults first (unlike its
668+
// no-arg constructor and unlike WebClientOptions(JsonObject)), so building
669+
// it directly from an empty or partial poolConfig leaves fields such as
670+
// maxLifetimeUnit null and triggers a NullPointerException when the
671+
// WebClient is created. Overlay poolConfig on the serialized defaults so
672+
// absent keys keep their documented values.
673+
PoolOptions poolOptions = new PoolOptions(new PoolOptions().toJson().mergeIn(poolConfig));
674+
return WebClient.create(vertx, new WebClientOptions(config), poolOptions);
668675
}
669676

670677

0 commit comments

Comments
 (0)