From 538a6ef49728d642b741478732ba7986db47f8fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Bl=C3=A1zquez?= Date: Thu, 20 Apr 2023 19:19:56 +0200 Subject: [PATCH] Revert "Replace `runCatching-map-getOrDefault` in caching (#2248)" This reverts commit da91066162e51ab5ed233cf75f2c620801014585. --- core/jvmMain/src/kotlinx/serialization/internal/Caching.kt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/core/jvmMain/src/kotlinx/serialization/internal/Caching.kt b/core/jvmMain/src/kotlinx/serialization/internal/Caching.kt index be46e65b73..a96f699492 100644 --- a/core/jvmMain/src/kotlinx/serialization/internal/Caching.kt +++ b/core/jvmMain/src/kotlinx/serialization/internal/Caching.kt @@ -17,12 +17,9 @@ import kotlin.reflect.KTypeProjection * but ClassValue is not available on Android, thus we attempt to check it dynamically * and fallback to ConcurrentHashMap-based cache. */ -private val useClassValue = try { +private val useClassValue = runCatching { Class.forName("java.lang.ClassValue") - true -} catch (_: Throwable) { - false -} +}.map { true }.getOrDefault(false) /** * Creates a **strongly referenced** cache of values associated with [Class].