From ea900c6e9b2b9456073fc8127c70fd8a68450f05 Mon Sep 17 00:00:00 2001 From: faraz152 <38698072+faraz152@users.noreply.github.com> Date: Mon, 30 Mar 2026 18:03:47 +0500 Subject: [PATCH] fix: avoid kotlin.time.Duration in CacheControl to fix Kotlin 2.3 compat Replace `Int.MAX_VALUE.seconds` with `maxStale(Int.MAX_VALUE, TimeUnit.SECONDS)` in `commonForceCache()`. The `.seconds` extension goes through internal stdlib methods (`Duration.Companion.fromRawValue`) whose mangled names changed in Kotlin 2.3, causing NoSuchMethodError at runtime when OkHttp (compiled with Kotlin 2.2.x) runs against Kotlin 2.3 stdlib. Using the TimeUnit-based overload avoids the kotlin.time.Duration code path entirely, making OkHttp binary-compatible across Kotlin 2.2.x and 2.3.x. Fixes #9347 --- .../kotlin/okhttp3/internal/-CacheControlCommon.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/okhttp/src/commonJvmAndroid/kotlin/okhttp3/internal/-CacheControlCommon.kt b/okhttp/src/commonJvmAndroid/kotlin/okhttp3/internal/-CacheControlCommon.kt index 5ccb68fd3c96..df554d3d56de 100644 --- a/okhttp/src/commonJvmAndroid/kotlin/okhttp3/internal/-CacheControlCommon.kt +++ b/okhttp/src/commonJvmAndroid/kotlin/okhttp3/internal/-CacheControlCommon.kt @@ -17,7 +17,7 @@ package okhttp3.internal -import kotlin.time.Duration.Companion.seconds +import java.util.concurrent.TimeUnit import okhttp3.CacheControl import okhttp3.Headers @@ -62,7 +62,7 @@ internal fun CacheControl.Companion.commonForceCache() = CacheControl .Builder() .onlyIfCached() - .maxStale(Int.MAX_VALUE.seconds) + .maxStale(Int.MAX_VALUE, TimeUnit.SECONDS) .build() internal fun CacheControl.Builder.commonBuild(): CacheControl =