Skip to content
Advertisement

java.lang.NoSuchFieldError: Companion when using `influx-client-reactive` and `quarkus`

Error occurs when instantiating a client

    InfluxDBClientReactive influxDBClient = InfluxDBClientReactiveFactory.create(
            influxConf.url(),
            influxConf.username(),
            influxConf.password().toCharArray());

dependency is excluded from quarkus-bom

implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}") {
    exclude group: "com.squareup.okhttp3", module: "okhttp"
}
implementation "com.influxdb:influxdb-client-reactive:6.4.0" 

otherwise (3.x.x) is forced and would cause

'okhttp3.RequestBody okhttp3.RequestBody.create(java.lang.String, okhttp3.MediaType)'
java.lang.NoSuchMethodError: 'okhttp3.RequestBody okhttp3.RequestBody.create(java.lang.String, okhttp3.MediaType)

at the same line.

trace:

Companion
java.lang.NoSuchFieldError: Companion
    at okhttp3.internal.Util.<clinit>(Util.kt:70)
    at okhttp3.HttpUrl$Builder.parse$okhttp(HttpUrl.kt:1239)
    at okhttp3.HttpUrl$Companion.get(HttpUrl.kt:1634)
    at okhttp3.HttpUrl$Companion.parse(HttpUrl.kt:1643)
    at okhttp3.HttpUrl.parse(HttpUrl.kt)
    at com.influxdb.client.InfluxDBClientOptions$Builder$ParsedUrl.<init>(InfluxDBClientOptions.java:689)
    at com.influxdb.client.InfluxDBClientOptions$Builder$ParsedUrl.<init>(InfluxDBClientOptions.java:681)
    at com.influxdb.client.InfluxDBClientOptions$Builder.connectionString(InfluxDBClientOptions.java:504)
    at com.influxdb.client.InfluxDBClientOptions$Builder.url(InfluxDBClientOptions.java:288)
    at com.influxdb.client.reactive.InfluxDBClientReactiveFactory.create(InfluxDBClientReactiveFactory.java:105)

Advertisement

Answer

This issue led me to think that com.squareup.okio:okio might also play a role here.

com.squareup.okio:okio:1.17.2
--- io.quarkus:quarkus-bom:2.11.2.Final
     --- runtimeClasspath

com.squareup.okio:okio:3.0.0 -> 1.17.2
--- com.squareup.okhttp3:okhttp:4.10.0

That Options.of is a call to method in that dependency and not Optional from java. That there is nothing strange here other than some quarkus necromancy forced for fabric8io/kubernetes-client

exclude group: "com.squareup.okio", module: "okio"

from quarkus-bom

Advertisement