paypal / mocca

Mocca is a GraphQL client for JVM languages with the goal of being easy to use, flexible and modular.
MIT License
15 stars 14 forks source link

Fix classpath issue caused by conflicting versions of OkHttp #61

Closed fabiocarvalho777 closed 2 years ago

fabiocarvalho777 commented 2 years ago

Apparently Mocca, when used with OkHttp, is bringing conflicting versions of Kotlin libraries, causing runtime issues to applications using Mocca with OkHttp. Here is an example of the exception:

Caused by: java.lang.NoSuchMethodError: kotlin.collections.ArraysKt.copyInto([B[BIII)[B
    at okio.Segment.writeTo(Segment.kt:169)
    at okio.Segment.compact(Segment.kt:152)
    at okio.Buffer.write(Buffer.kt:1842)
    at okio.Buffer.read(Buffer.kt:1854)
    at okio.Buffer.writeAll(Buffer.kt:1642)
    at okio.Options$Companion.buildTrieRecursive(Options.kt:187)
    at okio.Options$Companion.buildTrieRecursive(Options.kt:174)
    at okio.Options$Companion.buildTrieRecursive$default(Options.kt:113)
    at okio.Options$Companion.of(Options.kt:72)
    at okhttp3.internal.Util.<clinit>(Util.kt:70)
    at okhttp3.OkHttpClient.<clinit>(OkHttpClient.kt:1073)

And here is an example of the conflict (notice the okhttp version used by mocca-okhttp differs from the one used by feign-okhttp):

|    |    \--- com.paypal.mocca:mocca-okhttp:0.0.5
|    |         +--- com.squareup.okhttp3:okhttp:4.6.0 -> 4.9.2
|    |         |    +--- com.squareup.okio:okio:2.8.0
|    |         |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:1.4.0 -> 1.4.10
|    |         |    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib-common:1.4.10
|    |         |    |    |    \--- org.jetbrains:annotations:13.0
|    |         |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-common:1.4.0 -> 1.4.10
|    |         |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.4.10 (*)
|    |         +--- com.paypal.mocca:mocca-client:0.0.5 (*)
|    |         \--- io.github.openfeign:feign-okhttp:11.8
|    |              +--- io.github.openfeign:feign-core:11.8
|    |              \--- com.squareup.okhttp3:okhttp:4.9.2 (*)

Important notes

  1. For some reason this issue was not exposed during tests. Before fixing this problem, a test has to be added exposing this issue.
  2. This exact same problem likely happens with other HTTP clients as well. The reason for that is, at some point Feign was upgraded, but the HTTP clients were not, and they must always align with the versions used by Feign. Because of that, as part of this issue, MAKE SURE ALL HTTP CLIENTS VERSIONS ARE ALIGNED WITH THE ONES USED BY FEIGN.
fabiocarvalho777 commented 2 years ago

I believe now, although the HTTP clients versions do need to be upgraded and aligned with Feign, the specific classpath issue mentioned above was caused by the application using Mocca, which brought a very old version of org.jetbrains.kotlin:kotlin-stdlib (1.2.71).