Skip to content

Commit 29ff211

Browse files
manusaclaude
andauthored
fix(httpclient): correct factory priorities and add Vert.x 5 runtime validation (7442)
fix(httpclient): correct HTTP client factory priorities VertxHttpClientFactory is now the default HTTP client but was missing the priority -1 that indicates it's the project default. OkHttpClientFactory was still using priority -1 from when it was the default. This fix: - Adds priority() returning -1 to VertxHttpClientFactory (new default) - Removes priority() override from OkHttpClientFactory (now uses default 0) This ensures deterministic factory selection when multiple HTTP clients are on the classpath - the default Vert.x client will always be preferred unless a higher priority client is present. Fixes #7174 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --- fix(httpclient-vertx-5): add runtime check and documentation for Vert.x version compatibility Add runtime validation in Vertx5HttpClientFactory.newBuilder() to detect when Vert.x 5 classes are not available on the classpath. This provides a clear error message instead of cryptic NoClassDefFoundError when both kubernetes-httpclient-vertx (Vert.x 4) and kubernetes-httpclient-vertx-5 (Vert.x 5) are present but Maven resolves Vert.x 4 JARs. Also add detailed documentation in CHANGELOG explaining: - The mutual exclusivity of the two Vert.x HTTP client modules - How to properly configure Vert.x 5 with exclusions and property override - The root cause of the classpath conflict Fixes #7174 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 4db093a commit 29ff211

File tree

4 files changed

+82
-6
lines changed

4 files changed

+82
-6
lines changed

CHANGELOG.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
#### Bugs
66
* Fix #5292: Cluster() configuration should use tlsServerName
7+
* Fix #7174: (httpclient) Fix HTTP client factory priority - VertxHttpClientFactory (default) now has priority -1, OkHttpClientFactory restored to priority 0
8+
* Fix #7174: (httpclient-vertx-5) Add runtime check for Vert.x 5 classes to provide clear error when Vert.x 4/5 conflict occurs
9+
* Fix #7174: (chaos-tests) Fix classpath conflict when testing with Vert.x 5 HTTP client
710
* Fix #7415: (java-generator) Fix generic type erasure for array of enums with default values
811

912
#### Improvements
@@ -16,6 +19,42 @@
1619

1720
#### _**Note**_: Breaking changes
1821

22+
#### _**Note**_: Vert.x HTTP Client Compatibility (Issue #7174)
23+
24+
The `kubernetes-httpclient-vertx` (Vert.x 4.x) and `kubernetes-httpclient-vertx-5` (Vert.x 5.x) modules are **mutually exclusive**.
25+
They must not be included together in your project dependencies.
26+
Both modules provide an implementation of `HttpClient.Factory` and use the same `io.vertx` artifact coordinates but with incompatible major versions.
27+
28+
**Problem**: If both modules are present on the classpath, Maven's dependency resolution may pick Vert.x 4.x JARs while the `Vertx5HttpClientFactory` is selected at runtime.
29+
This causes `NoClassDefFoundError` for Vert.x 5-specific classes like `io.vertx.core.impl.SysProps`.
30+
31+
**Solution**: Ensure your project includes only ONE of these modules:
32+
- `kubernetes-httpclient-vertx` (default, uses Vert.x 4.x) - included transitively via `kubernetes-client`
33+
- `kubernetes-httpclient-vertx-5` (optional, uses Vert.x 5.x) - requires explicit dependency and exclusion of vertx-4
34+
35+
When using Vert.x 5, exclude the default Vert.x 4 client and set the `vertx.version` property:
36+
```xml
37+
<properties>
38+
<vertx.version>${vertx5.version}</vertx.version> <!-- or explicit 5.0.7 -->
39+
</properties>
40+
<dependencies>
41+
<dependency>
42+
<groupId>io.fabric8</groupId>
43+
<artifactId>kubernetes-client</artifactId>
44+
<exclusions>
45+
<exclusion>
46+
<groupId>io.fabric8</groupId>
47+
<artifactId>kubernetes-httpclient-vertx</artifactId>
48+
</exclusion>
49+
</exclusions>
50+
</dependency>
51+
<dependency>
52+
<groupId>io.fabric8</groupId>
53+
<artifactId>kubernetes-httpclient-vertx-5</artifactId>
54+
</dependency>
55+
</dependencies>
56+
```
57+
1958
### 7.5.2 (2026-01-22)
2059

2160
#### Dependency Upgrade

httpclient-okhttp/src/main/java/io/fabric8/kubernetes/client/okhttp/OkHttpClientFactory.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@
2727

2828
public class OkHttpClientFactory implements HttpClient.Factory {
2929

30-
@Override
31-
public int priority() {
32-
return -1;
33-
}
34-
3530
/**
3631
* Subclasses may use this to apply a base configuration to the builder
3732
*/

httpclient-vertx-5/src/main/java/io/fabric8/kubernetes/client/vertx5/Vertx5HttpClientFactory.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,25 @@
1919
import io.vertx.core.Vertx;
2020

2121
/**
22-
* Vert.x implementation of {@link io.fabric8.kubernetes.client.http.HttpClient.Factory}.
22+
* Vert.x 5 implementation of {@link io.fabric8.kubernetes.client.http.HttpClient.Factory}.
2323
*
2424
* <p>
2525
* When constructed with a non‑null {@link Vertx} the same instance is reused for every
2626
* client; otherwise each {@link #newBuilder()} call will lazily create (and own) its own
2727
* Vert.x runtime.
2828
* </p>
29+
*
30+
* <p>
31+
* <strong>Important:</strong> This HTTP client requires Vert.x 5.x runtime classes.
32+
* It is mutually exclusive with {@code kubernetes-httpclient-vertx} (Vert.x 4.x).
33+
* Including both on the classpath will cause runtime errors due to incompatible
34+
* Vert.x API versions. Ensure your project excludes one or the other.
35+
* </p>
2936
*/
3037
public class Vertx5HttpClientFactory implements HttpClient.Factory {
3138

39+
private static final String VERTX5_MARKER_CLASS = "io.vertx.core.impl.SysProps";
40+
3241
final Vertx vertx;
3342

3443
/**
@@ -53,9 +62,37 @@ public Vertx5HttpClientFactory(final Vertx vertx) {
5362
/**
5463
* {@inheritDoc} – reuses the shared Vert.x when present, otherwise defers creation to the
5564
* builder.
65+
*
66+
* @throws IllegalStateException if Vert.x 5 runtime classes are not available on the classpath
5667
*/
5768
@Override
5869
public Vertx5HttpClientBuilder<Vertx5HttpClientFactory> newBuilder() {
70+
validateVertx5Runtime();
5971
return new Vertx5HttpClientBuilder<>(this, vertx);
6072
}
73+
74+
/**
75+
* Validates that Vert.x 5 runtime classes are available on the classpath.
76+
*
77+
* <p>
78+
* This check prevents cryptic {@link NoClassDefFoundError} when both
79+
* {@code kubernetes-httpclient-vertx} (Vert.x 4) and {@code kubernetes-httpclient-vertx-5}
80+
* are on the classpath, but Maven dependency resolution picks Vert.x 4 JARs.
81+
* </p>
82+
*
83+
* @throws IllegalStateException if Vert.x 5 runtime is not available
84+
*/
85+
private static void validateVertx5Runtime() {
86+
try {
87+
Class.forName(VERTX5_MARKER_CLASS);
88+
} catch (ClassNotFoundException e) {
89+
throw new IllegalStateException(
90+
"Vert.x 5 runtime classes not found. The kubernetes-httpclient-vertx-5 module requires "
91+
+ "Vert.x 5.x on the classpath. This error typically occurs when both kubernetes-httpclient-vertx "
92+
+ "(Vert.x 4) and kubernetes-httpclient-vertx-5 (Vert.x 5) are present, causing Maven to resolve "
93+
+ "Vert.x 4 JARs. These modules are mutually exclusive - please exclude one from your dependencies "
94+
+ "and ensure vertx.version property is set appropriately (5.x for vertx-5, 4.x for vertx).",
95+
e);
96+
}
97+
}
6198
}

httpclient-vertx/src/main/java/io/fabric8/kubernetes/client/vertx/VertxHttpClientFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public class VertxHttpClientFactory implements io.fabric8.kubernetes.client.http
2323

2424
final Vertx sharedVertx;
2525

26+
@Override
27+
public int priority() {
28+
return -1;
29+
}
30+
2631
public VertxHttpClientFactory() {
2732
this(null);
2833
}

0 commit comments

Comments
 (0)